`include "chunjun_define.sv" 
`include "chunjun_lib_define.sv" 

//================================================================================================
// File Name   : wing_cbb_prefix_counter.sv
// Description : Find the oldest entry in the queue
//================================================================================================
module wing_cbb_age_matrix
#(
    parameter ENTRY_NUM = 6,
    parameter WR_NUM = 2,
    parameter FIND_OLDEST = 1,
    parameter RD_NUM_OLD = 2,
    parameter FIND_NEWEST = 1,
    parameter RD_NUM_NEW = 1,
    parameter VLD_VEC_NUM_OLD = 1,
    parameter VLD_VEC_NUM_NEW = 2
)
(
    input   logic       clk,
    input   logic       rst_n,
    input   logic [WR_NUM-1:0] wr_en, //write enalbe
    input   logic [WR_NUM-1:0][$clog2(ENTRY_NUM)-1:0] wr_id, //write index
    output  logic [VLD_VEC_NUM_OLD-1:0][RD_NUM_OLD-1:0][ENTRY_NUM-1:0] oldest_rd_oh, //oldest entry vec
    output  logic [VLD_VEC_NUM_NEW-1:0][RD_NUM_NEW-1:0][ENTRY_NUM-1:0] newest_rd_oh, //newest entry vec
    input   logic [VLD_VEC_NUM_OLD-1:0][ENTRY_NUM-1:0] oldest_vld_vec, //oldest entry's valid vec
    input   logic [VLD_VEC_NUM_NEW-1:0][ENTRY_NUM-1:0] newest_vld_vec //newest entry's valid vec
);
if(ENTRY_NUM == 6 && WR_NUM == 2 && RD_NUM_OLD == 2 && RD_NUM_NEW == 1 && VLD_VEC_NUM_OLD == 1 && VLD_VEC_NUM_NEW == 2) begin : age_matrix_gen_6_2_2_1_1_2
    logic [1:0][4:0] write_vec_raw;
    logic [1:0][4:0] write_vec;
    logic [1:0][14:0]matrix_upd;
    logic [1:0][14:0]matrix_d;
    logic [14:0]     age_matri_q, age_matri_d, age_matri_upd;
    logic [5:0][4:0] age_vec_raw;
    logic [0:0][5:0][4:0] age_vec;
    logic [0:0][5:0][1:0] cnt_oh;
    logic [1:0][5:0][4:0] age_vec_n;
    logic [1:0][5:0][0:0] cnt_oh_n;
    // Write Vecs
    assign write_vec_raw[0] = 5'b11111;
    assign write_vec_raw[1] = 5'b11111;
    always_comb begin
        case (wr_id[0])
            3'd0: write_vec[0][4:0] = ~write_vec_raw[0][4:0];
            3'd1: write_vec[0][4:0] = {~write_vec_raw[0][4:1], write_vec_raw[0][0:0]};
            3'd2: write_vec[0][4:0] = {~write_vec_raw[0][4:2], write_vec_raw[0][1:0]};
            3'd3: write_vec[0][4:0] = {~write_vec_raw[0][4:3], write_vec_raw[0][2:0]};
            3'd4: write_vec[0][4:0] = {~write_vec_raw[0][4:4], write_vec_raw[0][3:0]};
            3'd5: write_vec[0][4:0] =  write_vec_raw[0][4:0];
            default: write_vec[0][4:0] = 5'bx;
        endcase
    end
    always_comb begin
        case (wr_id[1])
            3'd0: write_vec[1][4:0] = ~write_vec_raw[0][4:0];
            3'd1: write_vec[1][4:0] = {~write_vec_raw[1][4:1], write_vec_raw[1][0:0]};
            3'd2: write_vec[1][4:0] = {~write_vec_raw[1][4:2], write_vec_raw[1][1:0]};
            3'd3: write_vec[1][4:0] = {~write_vec_raw[1][4:3], write_vec_raw[1][2:0]};
            3'd4: write_vec[1][4:0] = {~write_vec_raw[1][4:4], write_vec_raw[1][3:0]};
            3'd5: write_vec[1][4:0] =  write_vec_raw[0][4:0];
            default: write_vec[1][4:0] = 5'bx;
        endcase
    end
    // Age Matrix Reg
    `WDFFER(age_matri_q[0], age_matri_d[0], age_matri_upd[0], clk, rst_n)
    `WDFFER(age_matri_q[1], age_matri_d[1], age_matri_upd[1], clk, rst_n)
    `WDFFER(age_matri_q[2], age_matri_d[2], age_matri_upd[2], clk, rst_n)
    `WDFFER(age_matri_q[3], age_matri_d[3], age_matri_upd[3], clk, rst_n)
    `WDFFER(age_matri_q[4], age_matri_d[4], age_matri_upd[4], clk, rst_n)
    `WDFFER(age_matri_q[5], age_matri_d[5], age_matri_upd[5], clk, rst_n)
    `WDFFER(age_matri_q[6], age_matri_d[6], age_matri_upd[6], clk, rst_n)
    `WDFFER(age_matri_q[7], age_matri_d[7], age_matri_upd[7], clk, rst_n)
    `WDFFER(age_matri_q[8], age_matri_d[8], age_matri_upd[8], clk, rst_n)
    `WDFFER(age_matri_q[9], age_matri_d[9], age_matri_upd[9], clk, rst_n)
    `WDFFER(age_matri_q[10], age_matri_d[10], age_matri_upd[10], clk, rst_n)
    `WDFFER(age_matri_q[11], age_matri_d[11], age_matri_upd[11], clk, rst_n)
    `WDFFER(age_matri_q[12], age_matri_d[12], age_matri_upd[12], clk, rst_n)
    `WDFFER(age_matri_q[13], age_matri_d[13], age_matri_upd[13], clk, rst_n)
    `WDFFER(age_matri_q[14], age_matri_d[14], age_matri_upd[14], clk, rst_n)
    always_comb begin
        matrix_upd[0] = 15'b0;
        case (wr_id[0])
            3'd0: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][6] = wr_en[0];
                matrix_upd[0][10] = wr_en[0];
            end
            3'd1: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][7] = wr_en[0];
                matrix_upd[0][11] = wr_en[0];
            end
            3'd2: begin
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
                matrix_upd[0][8] = wr_en[0];
                matrix_upd[0][12] = wr_en[0];
            end
            3'd3: begin
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
                matrix_upd[0][9] = wr_en[0];
                matrix_upd[0][13] = wr_en[0];
            end
            3'd4: begin
                matrix_upd[0][6] = wr_en[0];
                matrix_upd[0][7] = wr_en[0];
                matrix_upd[0][8] = wr_en[0];
                matrix_upd[0][9] = wr_en[0];
                matrix_upd[0][14] = wr_en[0];
            end
            3'd5: begin
                matrix_upd[0][10] = wr_en[0];
                matrix_upd[0][11] = wr_en[0];
                matrix_upd[0][12] = wr_en[0];
                matrix_upd[0][13] = wr_en[0];
                matrix_upd[0][14] = wr_en[0];
            end
        endcase
    end
    always_comb begin
        matrix_upd[1] = 15'b0;
        case (wr_id[1])
            3'd0: begin
                matrix_upd[1][0] = wr_en[1];
                matrix_upd[1][1] = wr_en[1];
                matrix_upd[1][3] = wr_en[1];
                matrix_upd[1][6] = wr_en[1];
                matrix_upd[1][10] = wr_en[1];
            end
            3'd1: begin
                matrix_upd[1][0] = wr_en[1];
                matrix_upd[1][2] = wr_en[1];
                matrix_upd[1][4] = wr_en[1];
                matrix_upd[1][7] = wr_en[1];
                matrix_upd[1][11] = wr_en[1];
            end
            3'd2: begin
                matrix_upd[1][1] = wr_en[1];
                matrix_upd[1][2] = wr_en[1];
                matrix_upd[1][5] = wr_en[1];
                matrix_upd[1][8] = wr_en[1];
                matrix_upd[1][12] = wr_en[1];
            end
            3'd3: begin
                matrix_upd[1][3] = wr_en[1];
                matrix_upd[1][4] = wr_en[1];
                matrix_upd[1][5] = wr_en[1];
                matrix_upd[1][9] = wr_en[1];
                matrix_upd[1][13] = wr_en[1];
            end
            3'd4: begin
                matrix_upd[1][6] = wr_en[1];
                matrix_upd[1][7] = wr_en[1];
                matrix_upd[1][8] = wr_en[1];
                matrix_upd[1][9] = wr_en[1];
                matrix_upd[1][14] = wr_en[1];
            end    
            3'd5: begin
                matrix_upd[1][10] = wr_en[1];
                matrix_upd[1][11] = wr_en[1];
                matrix_upd[1][12] = wr_en[1];
                matrix_upd[1][13] = wr_en[1];
                matrix_upd[1][14] = wr_en[1];
            end
        endcase
    end
    assign age_matri_upd = matrix_upd[0] | matrix_upd[1];
    always_comb begin
        matrix_d[0] = 15'b0;
        case (wr_id[0])
            3'd0: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][1] = write_vec[0][1];
                matrix_d[0][3] = write_vec[0][2];
                matrix_d[0][6] = write_vec[0][3];
                matrix_d[0][10] = write_vec[0][4];
            end
            3'd1: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][4] = write_vec[0][2];
                matrix_d[0][7] = write_vec[0][3];
                matrix_d[0][11] = write_vec[0][4];
            end
            3'd2: begin
                matrix_d[0][1] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
                matrix_d[0][8] = write_vec[0][3];
                matrix_d[0][12] = write_vec[0][4];
            end
            3'd3: begin
                matrix_d[0][3] = write_vec[0][0];
                matrix_d[0][4] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
                matrix_d[0][9] = write_vec[0][3];
                matrix_d[0][13] = write_vec[0][4];
            end
            3'd4: begin
                matrix_d[0][6] = write_vec[0][0];
                matrix_d[0][7] = write_vec[0][1];
                matrix_d[0][8] = write_vec[0][2];
                matrix_d[0][9] = write_vec[0][3];
                matrix_d[0][14] = write_vec[0][4];
            end
            3'd5: begin
                matrix_d[0][10] = write_vec[0][0];
                matrix_d[0][11] = write_vec[0][1];
                matrix_d[0][12] = write_vec[0][2];
                matrix_d[0][13] = write_vec[0][3];
                matrix_d[0][14] = write_vec[0][4];
            end
        endcase
    end
    always_comb begin
        matrix_d[1] = 15'b0;
        case (wr_id[1])
            3'd0: begin
                matrix_d[1][0] = write_vec[1][0];
                matrix_d[1][1] = write_vec[1][1];
                matrix_d[1][3] = write_vec[1][2];
                matrix_d[1][6] = write_vec[1][3];
                matrix_d[1][10] = write_vec[1][4];
            end
            3'd1: begin
                matrix_d[1][0] = write_vec[1][0];
                matrix_d[1][2] = write_vec[1][1];
                matrix_d[1][4] = write_vec[1][2];
                matrix_d[1][7] = write_vec[1][3];
                matrix_d[1][11] = write_vec[1][4];
            end
            3'd2: begin
                matrix_d[1][1] = write_vec[1][0];
                matrix_d[1][2] = write_vec[1][1];
                matrix_d[1][5] = write_vec[1][2];
                matrix_d[1][8] = write_vec[1][3];
                matrix_d[1][12] = write_vec[1][4];
            end
            3'd3: begin
                matrix_d[1][3] = write_vec[1][0];
                matrix_d[1][4] = write_vec[1][1];
                matrix_d[1][5] = write_vec[1][2];
                matrix_d[1][9] = write_vec[1][3];
                matrix_d[1][13] = write_vec[1][4];
            end
            3'd4: begin
                matrix_d[1][6] = write_vec[1][0];
                matrix_d[1][7] = write_vec[1][1];
                matrix_d[1][8] = write_vec[1][2];
                matrix_d[1][9] = write_vec[1][3];
                matrix_d[1][14] = write_vec[1][4];
            end
            3'd5: begin
                matrix_d[1][10] = write_vec[1][0];
                matrix_d[1][11] = write_vec[1][1];
                matrix_d[1][12] = write_vec[1][2];
                matrix_d[1][13] = write_vec[1][3];
                matrix_d[1][14] = write_vec[1][4];
            end
        endcase
    end
    assign age_matri_d[0] = matrix_upd[1][0] ? matrix_d[1][0] : matrix_d[0][0];
    assign age_matri_d[1] = matrix_upd[1][1] ? matrix_d[1][1] : matrix_d[0][1];
    assign age_matri_d[2] = matrix_upd[1][2] ? matrix_d[1][2] : matrix_d[0][2];
    assign age_matri_d[3] = matrix_upd[1][3] ? matrix_d[1][3] : matrix_d[0][3];
    assign age_matri_d[4] = matrix_upd[1][4] ? matrix_d[1][4] : matrix_d[0][4];
    assign age_matri_d[5] = matrix_upd[1][5] ? matrix_d[1][5] : matrix_d[0][5];
    assign age_matri_d[6] = matrix_upd[1][6] ? matrix_d[1][6] : matrix_d[0][6];
    assign age_matri_d[7] = matrix_upd[1][7] ? matrix_d[1][7] : matrix_d[0][7];
    assign age_matri_d[8] = matrix_upd[1][8] ? matrix_d[1][8] : matrix_d[0][8];
    assign age_matri_d[9] = matrix_upd[1][9] ? matrix_d[1][9] : matrix_d[0][9];
    assign age_matri_d[10] = matrix_upd[1][10] ? matrix_d[1][10] : matrix_d[0][10];
    assign age_matri_d[11] = matrix_upd[1][11] ? matrix_d[1][11] : matrix_d[0][11];
    assign age_matri_d[12] = matrix_upd[1][12] ? matrix_d[1][12] : matrix_d[0][12];
    assign age_matri_d[13] = matrix_upd[1][13] ? matrix_d[1][13] : matrix_d[0][13];
    assign age_matri_d[14] = matrix_upd[1][14] ? matrix_d[1][14] : matrix_d[0][14];

    // Raw age vectors (without valid)
    assign age_vec_raw[0][0] = ~age_matri_q[0];
    assign age_vec_raw[0][1] = ~age_matri_q[1];
    assign age_vec_raw[0][2] = ~age_matri_q[3];
    assign age_vec_raw[0][3] = ~age_matri_q[6];
    assign age_vec_raw[0][4] = ~age_matri_q[10];
    assign age_vec_raw[1][0] =  age_matri_q[0];
    assign age_vec_raw[1][1] = ~age_matri_q[2];
    assign age_vec_raw[1][2] = ~age_matri_q[4];
    assign age_vec_raw[1][3] = ~age_matri_q[7];
    assign age_vec_raw[1][4] = ~age_matri_q[11];
    assign age_vec_raw[2][0] =  age_matri_q[1];
    assign age_vec_raw[2][1] =  age_matri_q[2];
    assign age_vec_raw[2][2] = ~age_matri_q[5];
    assign age_vec_raw[2][3] = ~age_matri_q[8];
    assign age_vec_raw[2][4] = ~age_matri_q[12];
    assign age_vec_raw[3][0] =  age_matri_q[3];
    assign age_vec_raw[3][1] =  age_matri_q[4];
    assign age_vec_raw[3][2] =  age_matri_q[5];
    assign age_vec_raw[3][3] = ~age_matri_q[9];
    assign age_vec_raw[3][4] = ~age_matri_q[13];
    assign age_vec_raw[4][0] =  age_matri_q[6];
    assign age_vec_raw[4][1] =  age_matri_q[7];
    assign age_vec_raw[4][2] =  age_matri_q[8];
    assign age_vec_raw[4][3] =  age_matri_q[9];
    assign age_vec_raw[4][4] = ~age_matri_q[14];
    assign age_vec_raw[5][0] =  age_matri_q[10];
    assign age_vec_raw[5][1] =  age_matri_q[11];
    assign age_vec_raw[5][2] =  age_matri_q[12];
    assign age_vec_raw[5][3] =  age_matri_q[13];
    assign age_vec_raw[5][4] =  age_matri_q[14];
 
    // Generate age vectors on the basis of valid vector
if(FIND_OLDEST==1)  begin: age_matrix_gen_6_2_2_1_1_2_oldest_agev_gen
    assign age_vec[0][0][0] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[0][0][1] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[0][0][2] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[0][0][3] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[0][3]);
    assign age_vec[0][0][4] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[0][4]);
    assign age_vec[0][1][0] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[0][1][1] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[0][1][2] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[0][1][3] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[1][3]);
    assign age_vec[0][1][4] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[1][4]);
    assign age_vec[0][2][0] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[0][2][1] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[0][2][2] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[0][2][3] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[2][3]);
    assign age_vec[0][2][4] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[2][4]);
    assign age_vec[0][3][0] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[0][3][1] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[0][3][2] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[0][3][3] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[3][3]);
    assign age_vec[0][3][4] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[3][4]);
    assign age_vec[0][4][0] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[4][0]);
    assign age_vec[0][4][1] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[4][1]);
    assign age_vec[0][4][2] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[4][2]);
    assign age_vec[0][4][3] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[4][3]);
    assign age_vec[0][4][4] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[4][4]);
    assign age_vec[0][5][0] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[5][0]);
    assign age_vec[0][5][1] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[5][1]);
    assign age_vec[0][5][2] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[5][2]);
    assign age_vec[0][5][3] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[5][3]);
    assign age_vec[0][5][4] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[5][4]);
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_6_2_2_1_1_2_newest_agev_gen
    assign age_vec_n[0][0][0] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[0][0]);
    assign age_vec_n[0][0][1] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[0][1]);
    assign age_vec_n[0][0][2] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[0][2]);
    assign age_vec_n[0][0][3] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[0][3]);
    assign age_vec_n[0][0][4] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[0][4]);
    assign age_vec_n[0][1][0] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[1][0]); 
    assign age_vec_n[0][1][1] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[1][1]);
    assign age_vec_n[0][1][2] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[1][2]);
    assign age_vec_n[0][1][3] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[1][3]);
    assign age_vec_n[0][1][4] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[1][4]);
    assign age_vec_n[0][2][0] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[2][0]);
    assign age_vec_n[0][2][1] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[2][1]);
    assign age_vec_n[0][2][2] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[2][2]);
    assign age_vec_n[0][2][3] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[2][3]);
    assign age_vec_n[0][2][4] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[2][4]);
    assign age_vec_n[0][3][0] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[3][0]);
    assign age_vec_n[0][3][1] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[3][1]);
    assign age_vec_n[0][3][2] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[3][2]);
    assign age_vec_n[0][3][3] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[3][3]);
    assign age_vec_n[0][3][4] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[3][4]);
    assign age_vec_n[0][4][0] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[4][0]);
    assign age_vec_n[0][4][1] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[4][1]);
    assign age_vec_n[0][4][2] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[4][2]);
    assign age_vec_n[0][4][3] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[4][3]);
    assign age_vec_n[0][4][4] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[4][4]);
    assign age_vec_n[0][5][0] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[5][0]);
    assign age_vec_n[0][5][1] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[5][1]);
    assign age_vec_n[0][5][2] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[5][2]);
    assign age_vec_n[0][5][3] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[5][3]);
    assign age_vec_n[0][5][4] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[5][4]);
    assign age_vec_n[1][0][0] = !newest_vld_vec[1][0] ? 1'b1 : (!newest_vld_vec[1][1] ? 1'b0 : ~age_vec_raw[0][0]);
    assign age_vec_n[1][0][1] = !newest_vld_vec[1][0] ? 1'b1 : (!newest_vld_vec[1][2] ? 1'b0 : ~age_vec_raw[0][1]);
    assign age_vec_n[1][0][2] = !newest_vld_vec[1][0] ? 1'b1 : (!newest_vld_vec[1][3] ? 1'b0 : ~age_vec_raw[0][2]);
    assign age_vec_n[1][0][3] = !newest_vld_vec[1][0] ? 1'b1 : (!newest_vld_vec[1][4] ? 1'b0 : ~age_vec_raw[0][3]);
    assign age_vec_n[1][0][4] = !newest_vld_vec[1][0] ? 1'b1 : (!newest_vld_vec[1][5] ? 1'b0 : ~age_vec_raw[0][4]);
    assign age_vec_n[1][1][0] = !newest_vld_vec[1][1] ? 1'b1 : (!newest_vld_vec[1][0] ? 1'b0 : ~age_vec_raw[1][0]);
    assign age_vec_n[1][1][1] = !newest_vld_vec[1][1] ? 1'b1 : (!newest_vld_vec[1][2] ? 1'b0 : ~age_vec_raw[1][1]);
    assign age_vec_n[1][1][2] = !newest_vld_vec[1][1] ? 1'b1 : (!newest_vld_vec[1][3] ? 1'b0 : ~age_vec_raw[1][2]);
    assign age_vec_n[1][1][3] = !newest_vld_vec[1][1] ? 1'b1 : (!newest_vld_vec[1][4] ? 1'b0 : ~age_vec_raw[1][3]);
    assign age_vec_n[1][1][4] = !newest_vld_vec[1][1] ? 1'b1 : (!newest_vld_vec[1][5] ? 1'b0 : ~age_vec_raw[1][4]);
    assign age_vec_n[1][2][0] = !newest_vld_vec[1][2] ? 1'b1 : (!newest_vld_vec[1][0] ? 1'b0 : ~age_vec_raw[2][0]);
    assign age_vec_n[1][2][1] = !newest_vld_vec[1][2] ? 1'b1 : (!newest_vld_vec[1][1] ? 1'b0 : ~age_vec_raw[2][1]);
    assign age_vec_n[1][2][2] = !newest_vld_vec[1][2] ? 1'b1 : (!newest_vld_vec[1][3] ? 1'b0 : ~age_vec_raw[2][2]);
    assign age_vec_n[1][2][3] = !newest_vld_vec[1][2] ? 1'b1 : (!newest_vld_vec[1][4] ? 1'b0 : ~age_vec_raw[2][3]);
    assign age_vec_n[1][2][4] = !newest_vld_vec[1][2] ? 1'b1 : (!newest_vld_vec[1][5] ? 1'b0 : ~age_vec_raw[2][4]);
    assign age_vec_n[1][3][0] = !newest_vld_vec[1][3] ? 1'b1 : (!newest_vld_vec[1][0] ? 1'b0 : ~age_vec_raw[3][0]);
    assign age_vec_n[1][3][1] = !newest_vld_vec[1][3] ? 1'b1 : (!newest_vld_vec[1][1] ? 1'b0 : ~age_vec_raw[3][1]);
    assign age_vec_n[1][3][2] = !newest_vld_vec[1][3] ? 1'b1 : (!newest_vld_vec[1][2] ? 1'b0 : ~age_vec_raw[3][2]);
    assign age_vec_n[1][3][3] = !newest_vld_vec[1][3] ? 1'b1 : (!newest_vld_vec[1][4] ? 1'b0 : ~age_vec_raw[3][3]);
    assign age_vec_n[1][3][4] = !newest_vld_vec[1][3] ? 1'b1 : (!newest_vld_vec[1][5] ? 1'b0 : ~age_vec_raw[3][4]);
    assign age_vec_n[1][4][0] = !newest_vld_vec[1][4] ? 1'b1 : (!newest_vld_vec[1][0] ? 1'b0 : ~age_vec_raw[4][0]);
    assign age_vec_n[1][4][1] = !newest_vld_vec[1][4] ? 1'b1 : (!newest_vld_vec[1][1] ? 1'b0 : ~age_vec_raw[4][1]);
    assign age_vec_n[1][4][2] = !newest_vld_vec[1][4] ? 1'b1 : (!newest_vld_vec[1][2] ? 1'b0 : ~age_vec_raw[4][2]);
    assign age_vec_n[1][4][3] = !newest_vld_vec[1][4] ? 1'b1 : (!newest_vld_vec[1][3] ? 1'b0 : ~age_vec_raw[4][3]);
    assign age_vec_n[1][4][4] = !newest_vld_vec[1][4] ? 1'b1 : (!newest_vld_vec[1][5] ? 1'b0 : ~age_vec_raw[4][4]);
    assign age_vec_n[1][5][0] = !newest_vld_vec[1][5] ? 1'b1 : (!newest_vld_vec[1][0] ? 1'b0 : ~age_vec_raw[5][0]);
    assign age_vec_n[1][5][1] = !newest_vld_vec[1][5] ? 1'b1 : (!newest_vld_vec[1][1] ? 1'b0 : ~age_vec_raw[5][1]);
    assign age_vec_n[1][5][2] = !newest_vld_vec[1][5] ? 1'b1 : (!newest_vld_vec[1][2] ? 1'b0 : ~age_vec_raw[5][2]);
    assign age_vec_n[1][5][3] = !newest_vld_vec[1][5] ? 1'b1 : (!newest_vld_vec[1][3] ? 1'b0 : ~age_vec_raw[5][3]);
    assign age_vec_n[1][5][4] = !newest_vld_vec[1][5] ? 1'b1 : (!newest_vld_vec[1][4] ? 1'b0 : ~age_vec_raw[5][4]);
end
if(FIND_OLDEST==1)  begin: age_matrix_gen_6_2_2_1_1_2_oldest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_5_1_u0_0 (
        .data(age_vec[0][0]),
        .cnt_oh(cnt_oh[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_5_1_u1_0 (
        .data(age_vec[0][1]),
        .cnt_oh(cnt_oh[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_5_1_u2_0 (
        .data(age_vec[0][2]),
        .cnt_oh(cnt_oh[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_5_1_u3_0 (
        .data(age_vec[0][3]),
        .cnt_oh(cnt_oh[0][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_5_1_u4_0 (
        .data(age_vec[0][4]),
        .cnt_oh(cnt_oh[0][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_5_1_u5_0 (
        .data(age_vec[0][5]),
        .cnt_oh(cnt_oh[0][5])
    );
    assign oldest_rd_oh[0][0] = {cnt_oh[0][5][0], cnt_oh[0][4][0], cnt_oh[0][3][0], cnt_oh[0][2][0], cnt_oh[0][1][0], cnt_oh[0][0][0]};
    assign oldest_rd_oh[0][1] = {cnt_oh[0][5][1], cnt_oh[0][4][1], cnt_oh[0][3][1], cnt_oh[0][2][1], cnt_oh[0][1][1], cnt_oh[0][0][1]};
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_6_2_2_1_1_2_newest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u0_0 (
        .data(age_vec_n[0][0]),
        .cnt_oh(cnt_oh_n[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u1_0 (
        .data(age_vec_n[0][1]),
        .cnt_oh(cnt_oh_n[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u2_0 (
        .data(age_vec_n[0][2]),
        .cnt_oh(cnt_oh_n[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u3_0 (
        .data(age_vec_n[0][3]),
        .cnt_oh(cnt_oh_n[0][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u4_0 (
        .data(age_vec_n[0][4]),
        .cnt_oh(cnt_oh_n[0][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u5_0 (
        .data(age_vec_n[0][5]),
        .cnt_oh(cnt_oh_n[0][5])
    );
    assign newest_rd_oh[0][0] = {cnt_oh_n[0][5][0], cnt_oh_n[0][4][0], cnt_oh_n[0][3][0], cnt_oh_n[0][2][0], cnt_oh_n[0][1][0], cnt_oh_n[0][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u0_1 (
        .data(age_vec_n[1][0]),
        .cnt_oh(cnt_oh_n[1][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u1_1 (
        .data(age_vec_n[1][1]),
        .cnt_oh(cnt_oh_n[1][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u2_1 (
        .data(age_vec_n[1][2]),
        .cnt_oh(cnt_oh_n[1][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u3_1 (
        .data(age_vec_n[1][3]),
        .cnt_oh(cnt_oh_n[1][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u4_1 (
        .data(age_vec_n[1][4]),
        .cnt_oh(cnt_oh_n[1][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u5_1 (
        .data(age_vec_n[1][5]),
        .cnt_oh(cnt_oh_n[1][5])
    );
    assign newest_rd_oh[1][0] = {cnt_oh_n[1][5][0], cnt_oh_n[1][4][0], cnt_oh_n[1][3][0], cnt_oh_n[1][2][0], cnt_oh_n[1][1][0], cnt_oh_n[1][0][0]};
end
if(FIND_OLDEST==0)  begin: age_matrix_gen_6_2_2_1_1_2_no_oldest
    assign age_vec = 'b0;
    assign cnt_oh = 'b0;
    assign oldest_rd_oh = 'b0;
end
if(FIND_NEWEST==0)  begin: age_matrix_gen_6_2_2_1_1_2_no_newest
    assign age_vec_n = 'b0;
    assign cnt_oh_n = 'b0;
    assign newest_rd_oh = 'b0;
end
end
if(ENTRY_NUM == 4 && WR_NUM == 1 && RD_NUM_OLD == 1 && RD_NUM_NEW == 1 && VLD_VEC_NUM_OLD == 5 && VLD_VEC_NUM_NEW == 1) begin : age_matrix_gen_4_1_1_1_5_1
    logic [0:0][2:0] write_vec_raw;
    logic [0:0][2:0] write_vec;
    logic [0:0][5:0]matrix_upd;
    logic [0:0][5:0]matrix_d;
    logic [5:0]     age_matri_q, age_matri_d, age_matri_upd;
    logic [3:0][2:0] age_vec_raw;
    logic [4:0][3:0][2:0] age_vec;
    logic [4:0][3:0][0:0] cnt_oh;
    logic [0:0][3:0][2:0] age_vec_n;
    logic [0:0][3:0][0:0] cnt_oh_n;
    // Write Vecs
    assign write_vec_raw[0] = 3'b111;
    always_comb begin
        case (wr_id[0])
            2'd0: write_vec[0][2:0] = ~write_vec_raw[0][2:0];
            2'd1: write_vec[0][2:0] = {~write_vec_raw[0][2:1], write_vec_raw[0][0:0]};
            2'd2: write_vec[0][2:0] = {~write_vec_raw[0][2:2], write_vec_raw[0][1:0]};
            2'd3: write_vec[0][2:0] =  write_vec_raw[0][2:0];
            default: write_vec[0][2:0] = 3'bx;
        endcase
    end
    // Age Matrix Reg
    `WDFFER(age_matri_q[0], age_matri_d[0], age_matri_upd[0], clk, rst_n)
    `WDFFER(age_matri_q[1], age_matri_d[1], age_matri_upd[1], clk, rst_n)
    `WDFFER(age_matri_q[2], age_matri_d[2], age_matri_upd[2], clk, rst_n)
    `WDFFER(age_matri_q[3], age_matri_d[3], age_matri_upd[3], clk, rst_n)
    `WDFFER(age_matri_q[4], age_matri_d[4], age_matri_upd[4], clk, rst_n)
    `WDFFER(age_matri_q[5], age_matri_d[5], age_matri_upd[5], clk, rst_n)
    always_comb begin
        matrix_upd[0] = 6'b0;
        case (wr_id[0])
            2'd0: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][3] = wr_en[0];
            end
            2'd1: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
            end
            2'd2: begin
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
            end
            2'd3: begin
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
            end
        endcase
    end
    assign age_matri_upd = matrix_upd[0];
    always_comb begin
        matrix_d[0] = 6'b0;
        case (wr_id[0])
            2'd0: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][1] = write_vec[0][1];
                matrix_d[0][3] = write_vec[0][2];
            end
            2'd1: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][4] = write_vec[0][2];
            end
            2'd2: begin
                matrix_d[0][1] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
            end
            2'd3: begin
                matrix_d[0][3] = write_vec[0][0];
                matrix_d[0][4] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
            end
        endcase
    end
    assign age_matri_d[0] = matrix_d[0][0];
    assign age_matri_d[1] = matrix_d[0][1];
    assign age_matri_d[2] = matrix_d[0][2];
    assign age_matri_d[3] = matrix_d[0][3];
    assign age_matri_d[4] = matrix_d[0][4];
    assign age_matri_d[5] = matrix_d[0][5];
 
    // Raw age vectors (without valid)
    assign age_vec_raw[0][0] = ~age_matri_q[0];
    assign age_vec_raw[0][1] = ~age_matri_q[1];
    assign age_vec_raw[0][2] = ~age_matri_q[3];
    assign age_vec_raw[1][0] =  age_matri_q[0];
    assign age_vec_raw[1][1] = ~age_matri_q[2];
    assign age_vec_raw[1][2] = ~age_matri_q[4];
    assign age_vec_raw[2][0] =  age_matri_q[1];
    assign age_vec_raw[2][1] =  age_matri_q[2];
    assign age_vec_raw[2][2] = ~age_matri_q[5];
    assign age_vec_raw[3][0] =  age_matri_q[3];
    assign age_vec_raw[3][1] =  age_matri_q[4];
    assign age_vec_raw[3][2] =  age_matri_q[5];
 
    // Generate age vectors on the basis of valid vector
if(FIND_OLDEST==1)  begin: age_matrix_gen_4_1_1_1_5_1_oldest_agev_gen
    assign age_vec[0][0][0] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[0][0][1] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[0][0][2] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[0][1][0] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[0][1][1] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[0][1][2] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[0][2][0] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[0][2][1] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[0][2][2] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[0][3][0] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[0][3][1] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[0][3][2] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[1][0][0] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[1][0][1] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[1][0][2] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[1][1][0] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[1][1][1] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[1][1][2] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[1][2][0] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[1][2][1] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[1][2][2] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[1][3][0] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[1][3][1] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[1][3][2] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[2][0][0] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[2][0][1] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[2][0][2] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[2][1][0] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[2][1][1] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[2][1][2] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[2][2][0] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[2][2][1] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[2][2][2] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[2][3][0] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[2][3][1] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[2][3][2] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[3][0][0] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[3][0][1] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[3][0][2] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[3][1][0] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[3][1][1] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[3][1][2] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[3][2][0] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[3][2][1] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[3][2][2] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[3][3][0] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[3][3][1] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[3][3][2] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[4][0][0] = !oldest_vld_vec[4][0] ? 1'b1 : (!oldest_vld_vec[4][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[4][0][1] = !oldest_vld_vec[4][0] ? 1'b1 : (!oldest_vld_vec[4][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[4][0][2] = !oldest_vld_vec[4][0] ? 1'b1 : (!oldest_vld_vec[4][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[4][1][0] = !oldest_vld_vec[4][1] ? 1'b1 : (!oldest_vld_vec[4][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[4][1][1] = !oldest_vld_vec[4][1] ? 1'b1 : (!oldest_vld_vec[4][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[4][1][2] = !oldest_vld_vec[4][1] ? 1'b1 : (!oldest_vld_vec[4][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[4][2][0] = !oldest_vld_vec[4][2] ? 1'b1 : (!oldest_vld_vec[4][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[4][2][1] = !oldest_vld_vec[4][2] ? 1'b1 : (!oldest_vld_vec[4][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[4][2][2] = !oldest_vld_vec[4][2] ? 1'b1 : (!oldest_vld_vec[4][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[4][3][0] = !oldest_vld_vec[4][3] ? 1'b1 : (!oldest_vld_vec[4][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[4][3][1] = !oldest_vld_vec[4][3] ? 1'b1 : (!oldest_vld_vec[4][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[4][3][2] = !oldest_vld_vec[4][3] ? 1'b1 : (!oldest_vld_vec[4][2] ? 1'b0 : age_vec_raw[3][2]);
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_4_1_1_1_5_1_newest_agev_gen
    assign age_vec_n[0][0][0] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[0][0]);
    assign age_vec_n[0][0][1] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[0][1]);
    assign age_vec_n[0][0][2] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[0][2]);
    assign age_vec_n[0][1][0] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[1][0]);
    assign age_vec_n[0][1][1] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[1][1]);
    assign age_vec_n[0][1][2] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[1][2]);
    assign age_vec_n[0][2][0] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[2][0]);
    assign age_vec_n[0][2][1] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[2][1]);
    assign age_vec_n[0][2][2] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[2][2]);
    assign age_vec_n[0][3][0] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[3][0]);
    assign age_vec_n[0][3][1] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[3][1]);
    assign age_vec_n[0][3][2] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[3][2]);
end
if(FIND_OLDEST==1)  begin: age_matrix_gen_4_1_1_1_5_1_oldest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_0 (
        .data(age_vec[0][0]),
        .cnt_oh(cnt_oh[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_0 (
        .data(age_vec[0][1]),
        .cnt_oh(cnt_oh[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_0 (
        .data(age_vec[0][2]),
        .cnt_oh(cnt_oh[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_0 (
        .data(age_vec[0][3]),
        .cnt_oh(cnt_oh[0][3])
    );
    assign oldest_rd_oh[0][0] = {cnt_oh[0][3][0], cnt_oh[0][2][0], cnt_oh[0][1][0], cnt_oh[0][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_1 (
        .data(age_vec[1][0]),
        .cnt_oh(cnt_oh[1][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_1 (
        .data(age_vec[1][1]),
        .cnt_oh(cnt_oh[1][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_1 (
        .data(age_vec[1][2]),
        .cnt_oh(cnt_oh[1][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_1 (
        .data(age_vec[1][3]),
        .cnt_oh(cnt_oh[1][3])
    );
    assign oldest_rd_oh[1][0] = {cnt_oh[1][3][0], cnt_oh[1][2][0], cnt_oh[1][1][0], cnt_oh[1][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_2 (
        .data(age_vec[2][0]),
        .cnt_oh(cnt_oh[2][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_2 (
        .data(age_vec[2][1]),
        .cnt_oh(cnt_oh[2][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_2 (
        .data(age_vec[2][2]),
        .cnt_oh(cnt_oh[2][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_2 (
        .data(age_vec[2][3]),
        .cnt_oh(cnt_oh[2][3])
    );
    assign oldest_rd_oh[2][0] = {cnt_oh[2][3][0], cnt_oh[2][2][0], cnt_oh[2][1][0], cnt_oh[2][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_3 (
        .data(age_vec[3][0]),
        .cnt_oh(cnt_oh[3][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_3 (
        .data(age_vec[3][1]),
        .cnt_oh(cnt_oh[3][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_3 (
        .data(age_vec[3][2]),
        .cnt_oh(cnt_oh[3][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_3 (
        .data(age_vec[3][3]),
        .cnt_oh(cnt_oh[3][3])
    );
    assign oldest_rd_oh[3][0] = {cnt_oh[3][3][0], cnt_oh[3][2][0], cnt_oh[3][1][0], cnt_oh[3][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_4 (
        .data(age_vec[4][0]),
        .cnt_oh(cnt_oh[4][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_4 (
        .data(age_vec[4][1]),
        .cnt_oh(cnt_oh[4][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_4 (
        .data(age_vec[4][2]),
        .cnt_oh(cnt_oh[4][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_4 (
        .data(age_vec[4][3]),
        .cnt_oh(cnt_oh[4][3])
    );
    assign oldest_rd_oh[4][0] = {cnt_oh[4][3][0], cnt_oh[4][2][0], cnt_oh[4][1][0], cnt_oh[4][0][0]};
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_4_1_1_1_5_1_newest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_0 (
        .data(age_vec_n[0][0]),
        .cnt_oh(cnt_oh_n[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_0 (
        .data(age_vec_n[0][1]),
        .cnt_oh(cnt_oh_n[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_0 (
        .data(age_vec_n[0][2]),
        .cnt_oh(cnt_oh_n[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_0 (
        .data(age_vec_n[0][3]),
        .cnt_oh(cnt_oh_n[0][3])
    );
    assign newest_rd_oh[0][0] = {cnt_oh_n[0][3][0], cnt_oh_n[0][2][0], cnt_oh_n[0][1][0], cnt_oh_n[0][0][0]};
end
if(FIND_OLDEST==0)  begin: age_matrix_gen_4_1_1_1_5_1_no_oldest
    assign age_vec = 'b0;
    assign cnt_oh = 'b0;
    assign oldest_rd_oh = 'b0;
end
if(FIND_NEWEST==0)  begin: age_matrix_gen_4_1_1_1_5_1_no_newest
    assign age_vec_n = 'b0;
    assign cnt_oh_n = 'b0;
    assign newest_rd_oh = 'b0;
end
end
if(ENTRY_NUM == 4 && WR_NUM == 1 && RD_NUM_OLD == 1 && RD_NUM_NEW == 1 && VLD_VEC_NUM_OLD == 1 && VLD_VEC_NUM_NEW == 1) begin : age_matrix_gen_4_1_1_1_1_1
    logic [0:0][2:0] write_vec_raw;
    logic [0:0][2:0] write_vec;
    logic [0:0][5:0]matrix_upd;
    logic [0:0][5:0]matrix_d;
    logic [5:0]     age_matri_q, age_matri_d, age_matri_upd;
    logic [3:0][2:0] age_vec_raw;
    logic [0:0][3:0][2:0] age_vec;
    logic [0:0][3:0][0:0] cnt_oh;
    logic [0:0][3:0][2:0] age_vec_n;
    logic [0:0][3:0][0:0] cnt_oh_n;
    // Write Vecs
    assign write_vec_raw[0] = 3'b111;
    always_comb begin
        case (wr_id[0])
            2'd0: write_vec[0][2:0] = ~write_vec_raw[0][2:0];
            2'd1: write_vec[0][2:0] = {~write_vec_raw[0][2:1], write_vec_raw[0][0:0]};
            2'd2: write_vec[0][2:0] = {~write_vec_raw[0][2:2], write_vec_raw[0][1:0]};
            2'd3: write_vec[0][2:0] =  write_vec_raw[0][2:0];
            default: write_vec[0][2:0] = 3'bx;
        endcase
    end
    // Age Matrix Reg
    `WDFFER(age_matri_q[0], age_matri_d[0], age_matri_upd[0], clk, rst_n)
    `WDFFER(age_matri_q[1], age_matri_d[1], age_matri_upd[1], clk, rst_n)
    `WDFFER(age_matri_q[2], age_matri_d[2], age_matri_upd[2], clk, rst_n)
    `WDFFER(age_matri_q[3], age_matri_d[3], age_matri_upd[3], clk, rst_n)
    `WDFFER(age_matri_q[4], age_matri_d[4], age_matri_upd[4], clk, rst_n)
    `WDFFER(age_matri_q[5], age_matri_d[5], age_matri_upd[5], clk, rst_n)
    always_comb begin
        matrix_upd[0] = 6'b0;
        case (wr_id[0])
            2'd0: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][3] = wr_en[0];
            end
            2'd1: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
            end
            2'd2: begin
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
            end
            2'd3: begin
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
            end
        endcase
    end
    assign age_matri_upd = matrix_upd[0];
    always_comb begin
        matrix_d[0] = 6'b0;
        case (wr_id[0])
            2'd0: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][1] = write_vec[0][1];
                matrix_d[0][3] = write_vec[0][2];
            end
            2'd1: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][4] = write_vec[0][2];
            end
            2'd2: begin
                matrix_d[0][1] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
            end
            2'd3: begin
                matrix_d[0][3] = write_vec[0][0];
                matrix_d[0][4] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
            end
        endcase
    end
    assign age_matri_d[0] = matrix_d[0][0];
    assign age_matri_d[1] = matrix_d[0][1];
    assign age_matri_d[2] = matrix_d[0][2];
    assign age_matri_d[3] = matrix_d[0][3];
    assign age_matri_d[4] = matrix_d[0][4];
    assign age_matri_d[5] = matrix_d[0][5];
 
     // Raw age vectors (without valid)
    assign age_vec_raw[0][0] = ~age_matri_q[0];
    assign age_vec_raw[0][1] = ~age_matri_q[1];
    assign age_vec_raw[0][2] = ~age_matri_q[3];
    assign age_vec_raw[1][0] =  age_matri_q[0];
    assign age_vec_raw[1][1] = ~age_matri_q[2];
    assign age_vec_raw[1][2] = ~age_matri_q[4];
    assign age_vec_raw[2][0] =  age_matri_q[1];
    assign age_vec_raw[2][1] =  age_matri_q[2];
    assign age_vec_raw[2][2] = ~age_matri_q[5];
    assign age_vec_raw[3][0] =  age_matri_q[3];
    assign age_vec_raw[3][1] =  age_matri_q[4];
    assign age_vec_raw[3][2] =  age_matri_q[5];
 
     // Generate age vectors on the basis of valid vector
if(FIND_OLDEST==1)  begin: age_matrix_gen_4_1_1_1_1_1_oldest_agev_gen
    assign age_vec[0][0][0] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[0][0][1] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[0][0][2] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[0][1][0] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[0][1][1] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[0][1][2] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[0][2][0] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[0][2][1] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[0][2][2] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[0][3][0] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[0][3][1] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[0][3][2] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[3][2]);
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_4_1_1_1_1_1_newest_agev_gen
    assign age_vec_n[0][0][0] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[0][0]);
    assign age_vec_n[0][0][1] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[0][1]);
    assign age_vec_n[0][0][2] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[0][2]);
    assign age_vec_n[0][1][0] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[1][0]);
    assign age_vec_n[0][1][1] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[1][1]);
    assign age_vec_n[0][1][2] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[1][2]);
    assign age_vec_n[0][2][0] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[2][0]);
    assign age_vec_n[0][2][1] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[2][1]);
    assign age_vec_n[0][2][2] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[2][2]);
    assign age_vec_n[0][3][0] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[3][0]);
    assign age_vec_n[0][3][1] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[3][1]);
    assign age_vec_n[0][3][2] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[3][2]);
end
if(FIND_OLDEST==1)  begin: age_matrix_gen_4_1_1_1_1_1_oldest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_0 (
        .data(age_vec[0][0]),
        .cnt_oh(cnt_oh[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_0 (
        .data(age_vec[0][1]),
        .cnt_oh(cnt_oh[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_0 (
        .data(age_vec[0][2]),
        .cnt_oh(cnt_oh[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_0 (
        .data(age_vec[0][3]),
        .cnt_oh(cnt_oh[0][3])
    );
    assign oldest_rd_oh[0][0] = {cnt_oh[0][3][0], cnt_oh[0][2][0], cnt_oh[0][1][0], cnt_oh[0][0][0]};
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_4_1_1_1_1_1_newest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_0 (
        .data(age_vec_n[0][0]),
        .cnt_oh(cnt_oh_n[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_0 (
        .data(age_vec_n[0][1]),
        .cnt_oh(cnt_oh_n[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_0 (
        .data(age_vec_n[0][2]),
        .cnt_oh(cnt_oh_n[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_0 (
        .data(age_vec_n[0][3]),
        .cnt_oh(cnt_oh_n[0][3])
    );
    assign newest_rd_oh[0][0] = {cnt_oh_n[0][3][0], cnt_oh_n[0][2][0], cnt_oh_n[0][1][0], cnt_oh_n[0][0][0]};
end
if(FIND_OLDEST==0)  begin: age_matrix_gen_4_1_1_1_1_1_no_oldest
    assign age_vec = 'b0;
    assign cnt_oh = 'b0;
    assign oldest_rd_oh = 'b0;
end
if(FIND_NEWEST==0)  begin: age_matrix_gen_4_1_1_1_1_1_no_newest
    assign age_vec_n = 'b0;
    assign cnt_oh_n = 'b0;
    assign newest_rd_oh = 'b0;
end
end
if(ENTRY_NUM == 4 && WR_NUM == 1 && RD_NUM_OLD == 1 && RD_NUM_NEW == 1 && VLD_VEC_NUM_OLD == 2 && VLD_VEC_NUM_NEW == 1) begin : age_matrix_gen_4_1_1_1_2_1
    logic [0:0][2:0] write_vec_raw;
    logic [0:0][2:0] write_vec;
    logic [0:0][5:0]matrix_upd;
    logic [0:0][5:0]matrix_d;
    logic [5:0]     age_matri_q, age_matri_d, age_matri_upd;
    logic [3:0][2:0] age_vec_raw;
    logic [1:0][3:0][2:0] age_vec;
    logic [1:0][3:0][0:0] cnt_oh;
    logic [0:0][3:0][2:0] age_vec_n;
    logic [0:0][3:0][0:0] cnt_oh_n;
    // Write Vecs
    assign write_vec_raw[0] = 3'b111;
    always_comb begin
        case (wr_id[0])
            2'd0: write_vec[0][2:0] = ~write_vec_raw[0][2:0];
            2'd1: write_vec[0][2:0] = {~write_vec_raw[0][2:1], write_vec_raw[0][0:0]};
            2'd2: write_vec[0][2:0] = {~write_vec_raw[0][2:2], write_vec_raw[0][1:0]};
            2'd3: write_vec[0][2:0] =  write_vec_raw[0][2:0];
            default: write_vec[0][2:0] = 3'bx;
        endcase
    end
    // Age Matrix Reg
    `WDFFER(age_matri_q[0], age_matri_d[0], age_matri_upd[0], clk, rst_n)
    `WDFFER(age_matri_q[1], age_matri_d[1], age_matri_upd[1], clk, rst_n)
    `WDFFER(age_matri_q[2], age_matri_d[2], age_matri_upd[2], clk, rst_n)
    `WDFFER(age_matri_q[3], age_matri_d[3], age_matri_upd[3], clk, rst_n)
    `WDFFER(age_matri_q[4], age_matri_d[4], age_matri_upd[4], clk, rst_n)
    `WDFFER(age_matri_q[5], age_matri_d[5], age_matri_upd[5], clk, rst_n)
    always_comb begin
        matrix_upd[0] = 6'b0;
        case (wr_id[0])
            2'd0: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][3] = wr_en[0];
            end
            2'd1: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
            end
            2'd2: begin
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
            end
            2'd3: begin
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
            end
        endcase
    end
    assign age_matri_upd = matrix_upd[0];
    always_comb begin
        matrix_d[0] = 6'b0;
        case (wr_id[0])
            2'd0: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][1] = write_vec[0][1];
                matrix_d[0][3] = write_vec[0][2];
            end
            2'd1: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][4] = write_vec[0][2];
            end
            2'd2: begin
                matrix_d[0][1] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
            end
            2'd3: begin
                matrix_d[0][3] = write_vec[0][0];
                matrix_d[0][4] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
            end
        endcase
    end
    assign age_matri_d[0] = matrix_d[0][0];
    assign age_matri_d[1] = matrix_d[0][1];
    assign age_matri_d[2] = matrix_d[0][2];
    assign age_matri_d[3] = matrix_d[0][3];
    assign age_matri_d[4] = matrix_d[0][4];
    assign age_matri_d[5] = matrix_d[0][5];
 
    // Raw age vectors (without valid)
    assign age_vec_raw[0][0] = ~age_matri_q[0];
    assign age_vec_raw[0][1] = ~age_matri_q[1];
    assign age_vec_raw[0][2] = ~age_matri_q[3];
    assign age_vec_raw[1][0] =  age_matri_q[0];
    assign age_vec_raw[1][1] = ~age_matri_q[2];
    assign age_vec_raw[1][2] = ~age_matri_q[4];
    assign age_vec_raw[2][0] =  age_matri_q[1];
    assign age_vec_raw[2][1] =  age_matri_q[2];
    assign age_vec_raw[2][2] = ~age_matri_q[5];
    assign age_vec_raw[3][0] =  age_matri_q[3];
    assign age_vec_raw[3][1] =  age_matri_q[4];
    assign age_vec_raw[3][2] =  age_matri_q[5];
 
    // Generate age vectors on the basis of valid vector
if(FIND_OLDEST==1)  begin: age_matrix_gen_4_1_1_1_2_1_oldest_agev_gen
    assign age_vec[0][0][0] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[0][0][1] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[0][0][2] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[0][1][0] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[0][1][1] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[0][1][2] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[0][2][0] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[0][2][1] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[0][2][2] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[0][3][0] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[0][3][1] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[0][3][2] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[1][0][0] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[1][0][1] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[1][0][2] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[1][1][0] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[1][1][1] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[1][1][2] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[1][2][0] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[1][2][1] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[1][2][2] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[1][3][0] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[1][3][1] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[1][3][2] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[3][2]);
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_4_1_1_1_2_1_newest_agev_gen
    assign age_vec_n[0][0][0] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[0][0]);
    assign age_vec_n[0][0][1] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[0][1]);
    assign age_vec_n[0][0][2] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[0][2]);
    assign age_vec_n[0][1][0] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[1][0]);
    assign age_vec_n[0][1][1] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[1][1]);
    assign age_vec_n[0][1][2] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[1][2]);
    assign age_vec_n[0][2][0] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[2][0]);
    assign age_vec_n[0][2][1] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[2][1]);
    assign age_vec_n[0][2][2] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[2][2]);
    assign age_vec_n[0][3][0] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[3][0]);
    assign age_vec_n[0][3][1] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[3][1]);
    assign age_vec_n[0][3][2] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[3][2]);
end
if(FIND_OLDEST==1)  begin: age_matrix_gen_4_1_1_1_2_1_oldest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_0 (
        .data(age_vec[0][0]),
        .cnt_oh(cnt_oh[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_0 (
        .data(age_vec[0][1]),
        .cnt_oh(cnt_oh[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_0 (
        .data(age_vec[0][2]),
        .cnt_oh(cnt_oh[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_0 (
        .data(age_vec[0][3]),
        .cnt_oh(cnt_oh[0][3])
    );
    assign oldest_rd_oh[0][0] = {cnt_oh[0][3][0], cnt_oh[0][2][0], cnt_oh[0][1][0], cnt_oh[0][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_1 (
        .data(age_vec[1][0]),
        .cnt_oh(cnt_oh[1][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_1 (
        .data(age_vec[1][1]),
        .cnt_oh(cnt_oh[1][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_1 (
        .data(age_vec[1][2]),
        .cnt_oh(cnt_oh[1][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_1 (
        .data(age_vec[1][3]),
        .cnt_oh(cnt_oh[1][3])
    );
    assign oldest_rd_oh[1][0] = {cnt_oh[1][3][0], cnt_oh[1][2][0], cnt_oh[1][1][0], cnt_oh[1][0][0]};
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_4_1_1_1_2_1_newest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_0 (
        .data(age_vec_n[0][0]),
        .cnt_oh(cnt_oh_n[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_0 (
        .data(age_vec_n[0][1]),
        .cnt_oh(cnt_oh_n[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_0 (
        .data(age_vec_n[0][2]),
        .cnt_oh(cnt_oh_n[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_0 (
        .data(age_vec_n[0][3]),
        .cnt_oh(cnt_oh_n[0][3])
    );
    assign newest_rd_oh[0][0] = {cnt_oh_n[0][3][0], cnt_oh_n[0][2][0], cnt_oh_n[0][1][0], cnt_oh_n[0][0][0]};
end
if(FIND_OLDEST==0)  begin: age_matrix_gen_4_1_1_1_2_1_no_oldest
    assign age_vec = 'b0;
    assign cnt_oh = 'b0;
    assign oldest_rd_oh = 'b0;
end
if(FIND_NEWEST==0)  begin: age_matrix_gen_4_1_1_1_2_1_no_newest
    assign age_vec_n = 'b0;
    assign cnt_oh_n = 'b0;
    assign newest_rd_oh = 'b0;
end
end
if(ENTRY_NUM == 2 && WR_NUM == 1 && RD_NUM_OLD == 1 && RD_NUM_NEW == 1 && VLD_VEC_NUM_OLD == 1 && VLD_VEC_NUM_NEW == 1) begin : age_matrix_gen_2_1_1_1_1_1
    logic [0:0][0:0] write_vec_raw;
    logic [0:0][0:0] write_vec;
    logic [0:0][0:0]matrix_upd;
    logic [0:0][0:0]matrix_d;
    logic [0:0]     age_matri_q, age_matri_d, age_matri_upd;
    logic [1:0][0:0] age_vec_raw;
    logic [0:0][1:0][0:0] age_vec;
    logic [0:0][1:0][0:0] cnt_oh;
    logic [0:0][1:0][0:0] age_vec_n;
    logic [0:0][1:0][0:0] cnt_oh_n;
    // Write Vecs
    assign write_vec_raw[0] = 1'b1;
    always_comb begin
        case (wr_id[0])
            1'd0: write_vec[0][0:0] = ~write_vec_raw[0][0:0];
            1'd1: write_vec[0][0:0] =  write_vec_raw[0][0:0];
            default: write_vec[0][0:0] = 1'bx;
        endcase
    end
    // Age Matrix Reg
    `WDFFER(age_matri_q[0], age_matri_d[0], age_matri_upd[0], clk, rst_n)
    always_comb begin
        matrix_upd[0] = 1'b0;
        case (wr_id[0])
            1'd0: begin
                matrix_upd[0][0] = wr_en[0];
            end
            1'd1: begin
                matrix_upd[0][0] = wr_en[0];
            end
        endcase
    end
    assign age_matri_upd = matrix_upd[0];
    always_comb begin
        matrix_d[0] = 1'b0;
        case (wr_id[0])
            1'd0: begin
                matrix_d[0][0] = write_vec[0][0];
            end
            1'd1: begin
                matrix_d[0][0] = write_vec[0][0];
            end
        endcase
    end
    assign age_matri_d[0] = matrix_d[0][0];
 
    // Raw age vectors (without valid)
    assign age_vec_raw[0][0] = ~age_matri_q[0];
    assign age_vec_raw[1][0] =  age_matri_q[0];
 
    // Generate age vectors on the basis of valid vector
if(FIND_OLDEST==1)  begin: age_matrix_gen_2_1_1_1_1_1_oldest_agev_gen
    assign age_vec[0][0][0] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[0][1][0] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[1][0]);
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_2_1_1_1_1_1_newest_agev_gen
    assign age_vec_n[0][0][0] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[0][0]);
    assign age_vec_n[0][1][0] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[1][0]);
end
if(FIND_OLDEST==1)  begin: age_matrix_gen_2_1_1_1_1_1_oldest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(1),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_1_0_u0_0 (
        .data(age_vec[0][0]),
        .cnt_oh(cnt_oh[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(1),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_1_0_u1_0 (
        .data(age_vec[0][1]),
        .cnt_oh(cnt_oh[0][1])
    );
    assign oldest_rd_oh[0][0] = {cnt_oh[0][1][0], cnt_oh[0][0][0]};
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_2_1_1_1_1_1_newest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(1),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_1_0_u0_0 (
        .data(age_vec_n[0][0]),
        .cnt_oh(cnt_oh_n[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(1),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_1_0_u1_0 (
        .data(age_vec_n[0][1]),
        .cnt_oh(cnt_oh_n[0][1])
    );
    assign newest_rd_oh[0][0] = {cnt_oh_n[0][1][0], cnt_oh_n[0][0][0]};
end
if(FIND_OLDEST==0)  begin: age_matrix_gen_2_1_1_1_1_1_no_oldest
    assign age_vec = 'b0;
    assign cnt_oh = 'b0;
    assign oldest_rd_oh = 'b0;
end
if(FIND_NEWEST==0)  begin: age_matrix_gen_2_1_1_1_1_1_no_newest
    assign age_vec_n = 'b0;
    assign cnt_oh_n = 'b0;
    assign newest_rd_oh = 'b0;
end
end
if(ENTRY_NUM == 6 && WR_NUM == 2 && RD_NUM_OLD == 1 && RD_NUM_NEW == 1 && VLD_VEC_NUM_OLD == 3 && VLD_VEC_NUM_NEW == 1) begin : age_matrix_gen_6_2_1_1_3_1
    logic [1:0][4:0] write_vec_raw;
    logic [1:0][4:0] write_vec;
    logic [1:0][14:0]matrix_upd;
    logic [1:0][14:0]matrix_d;
    logic [14:0]     age_matri_q, age_matri_d, age_matri_upd;
    logic [5:0][4:0] age_vec_raw;
    logic [2:0][5:0][4:0] age_vec;
    logic [2:0][5:0][0:0] cnt_oh;
    logic [0:0][5:0][4:0] age_vec_n;
    logic [0:0][5:0][0:0] cnt_oh_n;
    // Write Vecs
    assign write_vec_raw[0] = 5'b11111;
    assign write_vec_raw[1] = 5'b11111;
    always_comb begin
        case (wr_id[0])
            3'd0: write_vec[0][4:0] = ~write_vec_raw[0][4:0];
            3'd1: write_vec[0][4:0] = {~write_vec_raw[0][4:1], write_vec_raw[0][0:0]};
            3'd2: write_vec[0][4:0] = {~write_vec_raw[0][4:2], write_vec_raw[0][1:0]};
            3'd3: write_vec[0][4:0] = {~write_vec_raw[0][4:3], write_vec_raw[0][2:0]};
            3'd4: write_vec[0][4:0] = {~write_vec_raw[0][4:4], write_vec_raw[0][3:0]};
            3'd5: write_vec[0][4:0] =  write_vec_raw[0][4:0];
            default: write_vec[0][4:0] = 5'bx;
        endcase
    end
    always_comb begin
        case (wr_id[1])
            3'd0: write_vec[1][4:0] = ~write_vec_raw[0][4:0];
            3'd1: write_vec[1][4:0] = {~write_vec_raw[1][4:1], write_vec_raw[1][0:0]};
            3'd2: write_vec[1][4:0] = {~write_vec_raw[1][4:2], write_vec_raw[1][1:0]};
            3'd3: write_vec[1][4:0] = {~write_vec_raw[1][4:3], write_vec_raw[1][2:0]};
            3'd4: write_vec[1][4:0] = {~write_vec_raw[1][4:4], write_vec_raw[1][3:0]};
            3'd5: write_vec[1][4:0] =  write_vec_raw[0][4:0];
            default: write_vec[1][4:0] = 5'bx;
        endcase
    end
    // Age Matrix Reg
    `WDFFER(age_matri_q[0], age_matri_d[0], age_matri_upd[0], clk, rst_n)
    `WDFFER(age_matri_q[1], age_matri_d[1], age_matri_upd[1], clk, rst_n)
    `WDFFER(age_matri_q[2], age_matri_d[2], age_matri_upd[2], clk, rst_n)
    `WDFFER(age_matri_q[3], age_matri_d[3], age_matri_upd[3], clk, rst_n)
    `WDFFER(age_matri_q[4], age_matri_d[4], age_matri_upd[4], clk, rst_n)
    `WDFFER(age_matri_q[5], age_matri_d[5], age_matri_upd[5], clk, rst_n)
    `WDFFER(age_matri_q[6], age_matri_d[6], age_matri_upd[6], clk, rst_n)
    `WDFFER(age_matri_q[7], age_matri_d[7], age_matri_upd[7], clk, rst_n)
    `WDFFER(age_matri_q[8], age_matri_d[8], age_matri_upd[8], clk, rst_n)
    `WDFFER(age_matri_q[9], age_matri_d[9], age_matri_upd[9], clk, rst_n)
    `WDFFER(age_matri_q[10], age_matri_d[10], age_matri_upd[10], clk, rst_n)
    `WDFFER(age_matri_q[11], age_matri_d[11], age_matri_upd[11], clk, rst_n)
    `WDFFER(age_matri_q[12], age_matri_d[12], age_matri_upd[12], clk, rst_n)
    `WDFFER(age_matri_q[13], age_matri_d[13], age_matri_upd[13], clk, rst_n)
    `WDFFER(age_matri_q[14], age_matri_d[14], age_matri_upd[14], clk, rst_n)
    always_comb begin
        matrix_upd[0] = 15'b0;
        case (wr_id[0])
            3'd0: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][6] = wr_en[0];
                matrix_upd[0][10] = wr_en[0];
            end
            3'd1: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][7] = wr_en[0];
                matrix_upd[0][11] = wr_en[0];
            end
            3'd2: begin
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
                matrix_upd[0][8] = wr_en[0];
                matrix_upd[0][12] = wr_en[0];
            end
            3'd3: begin
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
                matrix_upd[0][9] = wr_en[0];
                matrix_upd[0][13] = wr_en[0];
            end
            3'd4: begin
                matrix_upd[0][6] = wr_en[0];
                matrix_upd[0][7] = wr_en[0];
                matrix_upd[0][8] = wr_en[0];
                matrix_upd[0][9] = wr_en[0];
                matrix_upd[0][14] = wr_en[0];
            end
            3'd5: begin
                matrix_upd[0][10] = wr_en[0];
                matrix_upd[0][11] = wr_en[0];
                matrix_upd[0][12] = wr_en[0];
                matrix_upd[0][13] = wr_en[0];
                matrix_upd[0][14] = wr_en[0];
            end
        endcase
    end
    always_comb begin
        matrix_upd[1] = 15'b0;
        case (wr_id[1])
            3'd0: begin
                matrix_upd[1][0] = wr_en[1];
                matrix_upd[1][1] = wr_en[1];
                matrix_upd[1][3] = wr_en[1];
                matrix_upd[1][6] = wr_en[1];
                matrix_upd[1][10] = wr_en[1];
            end
            3'd1: begin
                matrix_upd[1][0] = wr_en[1];
                matrix_upd[1][2] = wr_en[1];
                matrix_upd[1][4] = wr_en[1];
                matrix_upd[1][7] = wr_en[1];
                matrix_upd[1][11] = wr_en[1];
            end
            3'd2: begin
                matrix_upd[1][1] = wr_en[1];
                matrix_upd[1][2] = wr_en[1];
                matrix_upd[1][5] = wr_en[1];
                matrix_upd[1][8] = wr_en[1];
                matrix_upd[1][12] = wr_en[1];
            end
            3'd3: begin
                matrix_upd[1][3] = wr_en[1];
                matrix_upd[1][4] = wr_en[1];
                matrix_upd[1][5] = wr_en[1];
                matrix_upd[1][9] = wr_en[1];
                matrix_upd[1][13] = wr_en[1];
            end
            3'd4: begin
                matrix_upd[1][6] = wr_en[1];
                matrix_upd[1][7] = wr_en[1];
                matrix_upd[1][8] = wr_en[1];
                matrix_upd[1][9] = wr_en[1];
                matrix_upd[1][14] = wr_en[1];
            end
            3'd5: begin
                matrix_upd[1][10] = wr_en[1];
                matrix_upd[1][11] = wr_en[1];
                matrix_upd[1][12] = wr_en[1];
                matrix_upd[1][13] = wr_en[1];
                matrix_upd[1][14] = wr_en[1];
            end
        endcase
    end
    assign age_matri_upd = matrix_upd[0] | matrix_upd[1];
    always_comb begin
        matrix_d[0] = 15'b0;
        case (wr_id[0])
            3'd0: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][1] = write_vec[0][1];
                matrix_d[0][3] = write_vec[0][2];
                matrix_d[0][6] = write_vec[0][3];
                matrix_d[0][10] = write_vec[0][4];
            end
            3'd1: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][4] = write_vec[0][2];
                matrix_d[0][7] = write_vec[0][3];
                matrix_d[0][11] = write_vec[0][4];
            end
            3'd2: begin
                matrix_d[0][1] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
                matrix_d[0][8] = write_vec[0][3];
                matrix_d[0][12] = write_vec[0][4];
            end
            3'd3: begin
                matrix_d[0][3] = write_vec[0][0];
                matrix_d[0][4] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
                matrix_d[0][9] = write_vec[0][3];
                matrix_d[0][13] = write_vec[0][4];
            end
            3'd4: begin
                matrix_d[0][6] = write_vec[0][0];
                matrix_d[0][7] = write_vec[0][1];
                matrix_d[0][8] = write_vec[0][2];
                matrix_d[0][9] = write_vec[0][3];
                matrix_d[0][14] = write_vec[0][4];
            end
            3'd5: begin
                matrix_d[0][10] = write_vec[0][0];
                matrix_d[0][11] = write_vec[0][1];
                matrix_d[0][12] = write_vec[0][2];
                matrix_d[0][13] = write_vec[0][3];
                matrix_d[0][14] = write_vec[0][4];
            end
        endcase
    end
    always_comb begin
        matrix_d[1] = 15'b0;
        case (wr_id[1])
            3'd0: begin
                matrix_d[1][0] = write_vec[1][0];
                matrix_d[1][1] = write_vec[1][1];
                matrix_d[1][3] = write_vec[1][2];
                matrix_d[1][6] = write_vec[1][3];
                matrix_d[1][10] = write_vec[1][4];
            end
            3'd1: begin
                matrix_d[1][0] = write_vec[1][0];
                matrix_d[1][2] = write_vec[1][1];
                matrix_d[1][4] = write_vec[1][2];
                matrix_d[1][7] = write_vec[1][3];
                matrix_d[1][11] = write_vec[1][4];
            end
            3'd2: begin
                matrix_d[1][1] = write_vec[1][0];
                matrix_d[1][2] = write_vec[1][1];
                matrix_d[1][5] = write_vec[1][2];
                matrix_d[1][8] = write_vec[1][3];
                matrix_d[1][12] = write_vec[1][4];
            end
            3'd3: begin
                matrix_d[1][3] = write_vec[1][0];
                matrix_d[1][4] = write_vec[1][1];
                matrix_d[1][5] = write_vec[1][2];
                matrix_d[1][9] = write_vec[1][3];
                matrix_d[1][13] = write_vec[1][4];
            end
            3'd4: begin
                matrix_d[1][6] = write_vec[1][0];
                matrix_d[1][7] = write_vec[1][1];
                matrix_d[1][8] = write_vec[1][2];
                matrix_d[1][9] = write_vec[1][3];
                matrix_d[1][14] = write_vec[1][4];
            end
            3'd5: begin
                matrix_d[1][10] = write_vec[1][0];
                matrix_d[1][11] = write_vec[1][1];
                matrix_d[1][12] = write_vec[1][2];
                matrix_d[1][13] = write_vec[1][3];
                matrix_d[1][14] = write_vec[1][4];
            end
        endcase
    end
    assign age_matri_d[0] = matrix_upd[1][0] ? matrix_d[1][0] : matrix_d[0][0];
    assign age_matri_d[1] = matrix_upd[1][1] ? matrix_d[1][1] : matrix_d[0][1];
    assign age_matri_d[2] = matrix_upd[1][2] ? matrix_d[1][2] : matrix_d[0][2];
    assign age_matri_d[3] = matrix_upd[1][3] ? matrix_d[1][3] : matrix_d[0][3];
    assign age_matri_d[4] = matrix_upd[1][4] ? matrix_d[1][4] : matrix_d[0][4];
    assign age_matri_d[5] = matrix_upd[1][5] ? matrix_d[1][5] : matrix_d[0][5];
    assign age_matri_d[6] = matrix_upd[1][6] ? matrix_d[1][6] : matrix_d[0][6];
    assign age_matri_d[7] = matrix_upd[1][7] ? matrix_d[1][7] : matrix_d[0][7];
    assign age_matri_d[8] = matrix_upd[1][8] ? matrix_d[1][8] : matrix_d[0][8];
    assign age_matri_d[9] = matrix_upd[1][9] ? matrix_d[1][9] : matrix_d[0][9];
    assign age_matri_d[10] = matrix_upd[1][10] ? matrix_d[1][10] : matrix_d[0][10];
    assign age_matri_d[11] = matrix_upd[1][11] ? matrix_d[1][11] : matrix_d[0][11];
    assign age_matri_d[12] = matrix_upd[1][12] ? matrix_d[1][12] : matrix_d[0][12];
    assign age_matri_d[13] = matrix_upd[1][13] ? matrix_d[1][13] : matrix_d[0][13];
    assign age_matri_d[14] = matrix_upd[1][14] ? matrix_d[1][14] : matrix_d[0][14];

    // Raw age vectors (without valid)
    assign age_vec_raw[0][0] = ~age_matri_q[0];
    assign age_vec_raw[0][1] = ~age_matri_q[1];
    assign age_vec_raw[0][2] = ~age_matri_q[3];
    assign age_vec_raw[0][3] = ~age_matri_q[6];
    assign age_vec_raw[0][4] = ~age_matri_q[10];
    assign age_vec_raw[1][0] =  age_matri_q[0];
    assign age_vec_raw[1][1] = ~age_matri_q[2];
    assign age_vec_raw[1][2] = ~age_matri_q[4];
    assign age_vec_raw[1][3] = ~age_matri_q[7];
    assign age_vec_raw[1][4] = ~age_matri_q[11];
    assign age_vec_raw[2][0] =  age_matri_q[1];
    assign age_vec_raw[2][1] =  age_matri_q[2];
    assign age_vec_raw[2][2] = ~age_matri_q[5];
    assign age_vec_raw[2][3] = ~age_matri_q[8];
    assign age_vec_raw[2][4] = ~age_matri_q[12];
    assign age_vec_raw[3][0] =  age_matri_q[3];
    assign age_vec_raw[3][1] =  age_matri_q[4];
    assign age_vec_raw[3][2] =  age_matri_q[5];
    assign age_vec_raw[3][3] = ~age_matri_q[9];
    assign age_vec_raw[3][4] = ~age_matri_q[13];
    assign age_vec_raw[4][0] =  age_matri_q[6];
    assign age_vec_raw[4][1] =  age_matri_q[7];
    assign age_vec_raw[4][2] =  age_matri_q[8];
    assign age_vec_raw[4][3] =  age_matri_q[9];
    assign age_vec_raw[4][4] = ~age_matri_q[14];
    assign age_vec_raw[5][0] =  age_matri_q[10];
    assign age_vec_raw[5][1] =  age_matri_q[11];
    assign age_vec_raw[5][2] =  age_matri_q[12];
    assign age_vec_raw[5][3] =  age_matri_q[13];
    assign age_vec_raw[5][4] =  age_matri_q[14];

    // Generate age vectors on the basis of valid vector
if(FIND_OLDEST==1)  begin: age_matrix_gen_6_2_1_1_3_1_oldest_agev_gen
    assign age_vec[0][0][0] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[0][0][1] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[0][0][2] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[0][0][3] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[0][3]);
    assign age_vec[0][0][4] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[0][4]);
    assign age_vec[0][1][0] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[0][1][1] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[0][1][2] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[0][1][3] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[1][3]);
    assign age_vec[0][1][4] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[1][4]);
    assign age_vec[0][2][0] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[0][2][1] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[0][2][2] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[0][2][3] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[2][3]);
    assign age_vec[0][2][4] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[2][4]);
    assign age_vec[0][3][0] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[0][3][1] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[0][3][2] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[0][3][3] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[3][3]);
    assign age_vec[0][3][4] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[3][4]);
    assign age_vec[0][4][0] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[4][0]);
    assign age_vec[0][4][1] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[4][1]);
    assign age_vec[0][4][2] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[4][2]);
    assign age_vec[0][4][3] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[4][3]);
    assign age_vec[0][4][4] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[4][4]);
    assign age_vec[0][5][0] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[5][0]);
    assign age_vec[0][5][1] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[5][1]);
    assign age_vec[0][5][2] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[5][2]);
    assign age_vec[0][5][3] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[5][3]);
    assign age_vec[0][5][4] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[5][4]);
    assign age_vec[1][0][0] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[1][0][1] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[1][0][2] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[1][0][3] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[0][3]);
    assign age_vec[1][0][4] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[0][4]);
    assign age_vec[1][1][0] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[1][1][1] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[1][1][2] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[1][1][3] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[1][3]);
    assign age_vec[1][1][4] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[1][4]);
    assign age_vec[1][2][0] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[1][2][1] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[1][2][2] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[1][2][3] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[2][3]);
    assign age_vec[1][2][4] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[2][4]);
    assign age_vec[1][3][0] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[1][3][1] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[1][3][2] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[1][3][3] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[3][3]);
    assign age_vec[1][3][4] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[3][4]);
    assign age_vec[1][4][0] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[4][0]);
    assign age_vec[1][4][1] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[4][1]);
    assign age_vec[1][4][2] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[4][2]);
    assign age_vec[1][4][3] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[4][3]);
    assign age_vec[1][4][4] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[4][4]);
    assign age_vec[1][5][0] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[5][0]);
    assign age_vec[1][5][1] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[5][1]);
    assign age_vec[1][5][2] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[5][2]);
    assign age_vec[1][5][3] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[5][3]);
    assign age_vec[1][5][4] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[5][4]);
    assign age_vec[2][0][0] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[2][0][1] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[2][0][2] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[2][0][3] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[0][3]);
    assign age_vec[2][0][4] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[0][4]);
    assign age_vec[2][1][0] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[2][1][1] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[2][1][2] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[2][1][3] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[1][3]);
    assign age_vec[2][1][4] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[1][4]);
    assign age_vec[2][2][0] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[2][2][1] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[2][2][2] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[2][2][3] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[2][3]);
    assign age_vec[2][2][4] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[2][4]);
    assign age_vec[2][3][0] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[2][3][1] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[2][3][2] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[2][3][3] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[3][3]);
    assign age_vec[2][3][4] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[3][4]);
    assign age_vec[2][4][0] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[4][0]);
    assign age_vec[2][4][1] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[4][1]);
    assign age_vec[2][4][2] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[4][2]);
    assign age_vec[2][4][3] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[4][3]);
    assign age_vec[2][4][4] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[4][4]);
    assign age_vec[2][5][0] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[5][0]);
    assign age_vec[2][5][1] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[5][1]);
    assign age_vec[2][5][2] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[5][2]);
    assign age_vec[2][5][3] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[5][3]);
    assign age_vec[2][5][4] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[5][4]);
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_6_2_1_1_3_1_newest_agev_gen
    assign age_vec_n[0][0][0] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[0][0]);
    assign age_vec_n[0][0][1] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[0][1]);
    assign age_vec_n[0][0][2] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[0][2]);
    assign age_vec_n[0][0][3] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[0][3]);
    assign age_vec_n[0][0][4] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[0][4]);
    assign age_vec_n[0][1][0] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[1][0]);
    assign age_vec_n[0][1][1] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[1][1]);
    assign age_vec_n[0][1][2] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[1][2]);
    assign age_vec_n[0][1][3] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[1][3]);
    assign age_vec_n[0][1][4] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[1][4]);
    assign age_vec_n[0][2][0] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[2][0]);
    assign age_vec_n[0][2][1] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[2][1]);
    assign age_vec_n[0][2][2] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[2][2]);
    assign age_vec_n[0][2][3] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[2][3]);
    assign age_vec_n[0][2][4] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[2][4]);
    assign age_vec_n[0][3][0] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[3][0]);
    assign age_vec_n[0][3][1] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[3][1]);
    assign age_vec_n[0][3][2] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[3][2]);
    assign age_vec_n[0][3][3] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[3][3]);
    assign age_vec_n[0][3][4] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[3][4]);
    assign age_vec_n[0][4][0] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[4][0]);
    assign age_vec_n[0][4][1] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[4][1]);
    assign age_vec_n[0][4][2] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[4][2]);
    assign age_vec_n[0][4][3] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[4][3]);
    assign age_vec_n[0][4][4] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[4][4]);
    assign age_vec_n[0][5][0] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[5][0]);
    assign age_vec_n[0][5][1] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[5][1]);
    assign age_vec_n[0][5][2] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[5][2]);
    assign age_vec_n[0][5][3] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[5][3]);
    assign age_vec_n[0][5][4] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[5][4]);
end
if(FIND_OLDEST==1)  begin: age_matrix_gen_6_2_1_1_3_1_oldest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u0_0 (
        .data(age_vec[0][0]),
        .cnt_oh(cnt_oh[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u1_0 (
        .data(age_vec[0][1]),
        .cnt_oh(cnt_oh[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u2_0 (
        .data(age_vec[0][2]),
        .cnt_oh(cnt_oh[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u3_0 (
        .data(age_vec[0][3]),
        .cnt_oh(cnt_oh[0][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u4_0 (
        .data(age_vec[0][4]),
        .cnt_oh(cnt_oh[0][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u5_0 (
        .data(age_vec[0][5]),
        .cnt_oh(cnt_oh[0][5])
    );
    assign oldest_rd_oh[0][0] = {cnt_oh[0][5][0], cnt_oh[0][4][0], cnt_oh[0][3][0], cnt_oh[0][2][0], cnt_oh[0][1][0], cnt_oh[0][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u0_1 (
        .data(age_vec[1][0]),
        .cnt_oh(cnt_oh[1][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u1_1 (
        .data(age_vec[1][1]),
        .cnt_oh(cnt_oh[1][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u2_1 (
        .data(age_vec[1][2]),
        .cnt_oh(cnt_oh[1][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u3_1 (
        .data(age_vec[1][3]),
        .cnt_oh(cnt_oh[1][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u4_1 (
        .data(age_vec[1][4]),
        .cnt_oh(cnt_oh[1][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u5_1 (
        .data(age_vec[1][5]),
        .cnt_oh(cnt_oh[1][5])
    );
    assign oldest_rd_oh[1][0] = {cnt_oh[1][5][0], cnt_oh[1][4][0], cnt_oh[1][3][0], cnt_oh[1][2][0], cnt_oh[1][1][0], cnt_oh[1][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u0_2 (
        .data(age_vec[2][0]),
        .cnt_oh(cnt_oh[2][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u1_2 (
        .data(age_vec[2][1]),
        .cnt_oh(cnt_oh[2][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u2_2 (
        .data(age_vec[2][2]),
        .cnt_oh(cnt_oh[2][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u3_2 (
        .data(age_vec[2][3]),
        .cnt_oh(cnt_oh[2][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u4_2 (
        .data(age_vec[2][4]),
        .cnt_oh(cnt_oh[2][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u5_2 (
        .data(age_vec[2][5]),
        .cnt_oh(cnt_oh[2][5])
    );
    assign oldest_rd_oh[2][0] = {cnt_oh[2][5][0], cnt_oh[2][4][0], cnt_oh[2][3][0], cnt_oh[2][2][0], cnt_oh[2][1][0], cnt_oh[2][0][0]};
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_6_2_1_1_3_1_newest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u0_0 (
        .data(age_vec_n[0][0]),
        .cnt_oh(cnt_oh_n[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u1_0 (
        .data(age_vec_n[0][1]),
        .cnt_oh(cnt_oh_n[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u2_0 (
        .data(age_vec_n[0][2]),
        .cnt_oh(cnt_oh_n[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u3_0 (
        .data(age_vec_n[0][3]),
        .cnt_oh(cnt_oh_n[0][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u4_0 (
        .data(age_vec_n[0][4]),
        .cnt_oh(cnt_oh_n[0][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(5),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_5_0_u5_0 (
        .data(age_vec_n[0][5]),
        .cnt_oh(cnt_oh_n[0][5])
    );
    assign newest_rd_oh[0][0] = {cnt_oh_n[0][5][0], cnt_oh_n[0][4][0], cnt_oh_n[0][3][0], cnt_oh_n[0][2][0], cnt_oh_n[0][1][0], cnt_oh_n[0][0][0]};
end
if(FIND_OLDEST==0)  begin: age_matrix_gen_6_2_1_1_3_1_no_oldest
    assign age_vec = 'b0;
    assign cnt_oh = 'b0;
    assign oldest_rd_oh = 'b0;
end
if(FIND_NEWEST==0)  begin: age_matrix_gen_6_2_1_1_3_1_no_newest
    assign age_vec_n = 'b0;
    assign cnt_oh_n = 'b0;
    assign newest_rd_oh = 'b0;
end
end
if(ENTRY_NUM == 8 && WR_NUM == 2 && RD_NUM_OLD == 2 && RD_NUM_NEW == 1 && VLD_VEC_NUM_OLD == 4 && VLD_VEC_NUM_NEW == 1) begin : age_matrix_gen_8_2_2_1_4_1
    logic [1:0][6:0] write_vec_raw;
    logic [1:0][6:0] write_vec;
    logic [1:0][27:0]matrix_upd;
    logic [1:0][27:0]matrix_d;
    logic [27:0]     age_matri_q, age_matri_d, age_matri_upd;
    logic [7:0][6:0] age_vec_raw;
    logic [3:0][7:0][6:0] age_vec;
    logic [3:0][7:0][1:0] cnt_oh;
    logic [0:0][7:0][6:0] age_vec_n;
    logic [0:0][7:0][0:0] cnt_oh_n;
    // Write Vecs
    assign write_vec_raw[0] = 7'b1111111;
    assign write_vec_raw[1] = 7'b1111111;
    always_comb begin
        case (wr_id[0])
            3'd0: write_vec[0][6:0] = ~write_vec_raw[0][6:0];
            3'd1: write_vec[0][6:0] = {~write_vec_raw[0][6:1], write_vec_raw[0][0:0]};
            3'd2: write_vec[0][6:0] = {~write_vec_raw[0][6:2], write_vec_raw[0][1:0]};
            3'd3: write_vec[0][6:0] = {~write_vec_raw[0][6:3], write_vec_raw[0][2:0]};
            3'd4: write_vec[0][6:0] = {~write_vec_raw[0][6:4], write_vec_raw[0][3:0]};
            3'd5: write_vec[0][6:0] = {~write_vec_raw[0][6:5], write_vec_raw[0][4:0]};
            3'd6: write_vec[0][6:0] = {~write_vec_raw[0][6:6], write_vec_raw[0][5:0]};
            3'd7: write_vec[0][6:0] =  write_vec_raw[0][6:0];
            default: write_vec[0][6:0] = 7'bx;
        endcase
    end
    always_comb begin
        case (wr_id[1])
            3'd0: write_vec[1][6:0] = ~write_vec_raw[0][6:0];
            3'd1: write_vec[1][6:0] = {~write_vec_raw[1][6:1], write_vec_raw[1][0:0]};
            3'd2: write_vec[1][6:0] = {~write_vec_raw[1][6:2], write_vec_raw[1][1:0]};
            3'd3: write_vec[1][6:0] = {~write_vec_raw[1][6:3], write_vec_raw[1][2:0]};
            3'd4: write_vec[1][6:0] = {~write_vec_raw[1][6:4], write_vec_raw[1][3:0]};
            3'd5: write_vec[1][6:0] = {~write_vec_raw[1][6:5], write_vec_raw[1][4:0]};
            3'd6: write_vec[1][6:0] = {~write_vec_raw[1][6:6], write_vec_raw[1][5:0]};
            3'd7: write_vec[1][6:0] =  write_vec_raw[0][6:0];
            default: write_vec[1][6:0] = 7'bx;
        endcase
    end
    // Age Matrix Reg
    `WDFFER(age_matri_q[0], age_matri_d[0], age_matri_upd[0], clk, rst_n)
    `WDFFER(age_matri_q[1], age_matri_d[1], age_matri_upd[1], clk, rst_n)
    `WDFFER(age_matri_q[2], age_matri_d[2], age_matri_upd[2], clk, rst_n)
    `WDFFER(age_matri_q[3], age_matri_d[3], age_matri_upd[3], clk, rst_n)
    `WDFFER(age_matri_q[4], age_matri_d[4], age_matri_upd[4], clk, rst_n)
    `WDFFER(age_matri_q[5], age_matri_d[5], age_matri_upd[5], clk, rst_n)
    `WDFFER(age_matri_q[6], age_matri_d[6], age_matri_upd[6], clk, rst_n)
    `WDFFER(age_matri_q[7], age_matri_d[7], age_matri_upd[7], clk, rst_n)
    `WDFFER(age_matri_q[8], age_matri_d[8], age_matri_upd[8], clk, rst_n)
    `WDFFER(age_matri_q[9], age_matri_d[9], age_matri_upd[9], clk, rst_n)
    `WDFFER(age_matri_q[10], age_matri_d[10], age_matri_upd[10], clk, rst_n)
    `WDFFER(age_matri_q[11], age_matri_d[11], age_matri_upd[11], clk, rst_n)
    `WDFFER(age_matri_q[12], age_matri_d[12], age_matri_upd[12], clk, rst_n)
    `WDFFER(age_matri_q[13], age_matri_d[13], age_matri_upd[13], clk, rst_n)
    `WDFFER(age_matri_q[14], age_matri_d[14], age_matri_upd[14], clk, rst_n)
    `WDFFER(age_matri_q[15], age_matri_d[15], age_matri_upd[15], clk, rst_n)
    `WDFFER(age_matri_q[16], age_matri_d[16], age_matri_upd[16], clk, rst_n)
    `WDFFER(age_matri_q[17], age_matri_d[17], age_matri_upd[17], clk, rst_n)
    `WDFFER(age_matri_q[18], age_matri_d[18], age_matri_upd[18], clk, rst_n)
    `WDFFER(age_matri_q[19], age_matri_d[19], age_matri_upd[19], clk, rst_n)
    `WDFFER(age_matri_q[20], age_matri_d[20], age_matri_upd[20], clk, rst_n)
    `WDFFER(age_matri_q[21], age_matri_d[21], age_matri_upd[21], clk, rst_n)
    `WDFFER(age_matri_q[22], age_matri_d[22], age_matri_upd[22], clk, rst_n)
    `WDFFER(age_matri_q[23], age_matri_d[23], age_matri_upd[23], clk, rst_n)
    `WDFFER(age_matri_q[24], age_matri_d[24], age_matri_upd[24], clk, rst_n)
    `WDFFER(age_matri_q[25], age_matri_d[25], age_matri_upd[25], clk, rst_n)
    `WDFFER(age_matri_q[26], age_matri_d[26], age_matri_upd[26], clk, rst_n)
    `WDFFER(age_matri_q[27], age_matri_d[27], age_matri_upd[27], clk, rst_n)
    always_comb begin
        matrix_upd[0] = 28'b0;
        case (wr_id[0])
            3'd0: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][6] = wr_en[0];
                matrix_upd[0][10] = wr_en[0];
                matrix_upd[0][15] = wr_en[0];
                matrix_upd[0][21] = wr_en[0];
            end
            3'd1: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][7] = wr_en[0];
                matrix_upd[0][11] = wr_en[0];
                matrix_upd[0][16] = wr_en[0];
                matrix_upd[0][22] = wr_en[0];
            end
            3'd2: begin
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
                matrix_upd[0][8] = wr_en[0];
                matrix_upd[0][12] = wr_en[0];
                matrix_upd[0][17] = wr_en[0];
                matrix_upd[0][23] = wr_en[0];
            end
            3'd3: begin
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
                matrix_upd[0][9] = wr_en[0];
                matrix_upd[0][13] = wr_en[0];
                matrix_upd[0][18] = wr_en[0];
                matrix_upd[0][24] = wr_en[0];
            end
            3'd4: begin
                matrix_upd[0][6] = wr_en[0];
                matrix_upd[0][7] = wr_en[0];
                matrix_upd[0][8] = wr_en[0];
                matrix_upd[0][9] = wr_en[0];
                matrix_upd[0][14] = wr_en[0];
                matrix_upd[0][19] = wr_en[0];
                matrix_upd[0][25] = wr_en[0];
            end
            3'd5: begin
                matrix_upd[0][10] = wr_en[0];
                matrix_upd[0][11] = wr_en[0];
                matrix_upd[0][12] = wr_en[0];
                matrix_upd[0][13] = wr_en[0];
                matrix_upd[0][14] = wr_en[0];
                matrix_upd[0][20] = wr_en[0];
                matrix_upd[0][26] = wr_en[0];
            end
            3'd6: begin
                matrix_upd[0][15] = wr_en[0];
                matrix_upd[0][16] = wr_en[0];
                matrix_upd[0][17] = wr_en[0];
                matrix_upd[0][18] = wr_en[0];
                matrix_upd[0][19] = wr_en[0];
                matrix_upd[0][20] = wr_en[0];
                matrix_upd[0][27] = wr_en[0];
            end 
            3'd7: begin
                matrix_upd[0][21] = wr_en[0];
                matrix_upd[0][22] = wr_en[0];
                matrix_upd[0][23] = wr_en[0];
                matrix_upd[0][24] = wr_en[0];
                matrix_upd[0][25] = wr_en[0];
                matrix_upd[0][26] = wr_en[0];
                matrix_upd[0][27] = wr_en[0];
            end
        endcase
    end
    always_comb begin
        matrix_upd[1] = 28'b0;
        case (wr_id[1])
            3'd0: begin
                matrix_upd[1][0] = wr_en[1];
                matrix_upd[1][1] = wr_en[1];
                matrix_upd[1][3] = wr_en[1];
                matrix_upd[1][6] = wr_en[1];
                matrix_upd[1][10] = wr_en[1];
                matrix_upd[1][15] = wr_en[1];
                matrix_upd[1][21] = wr_en[1];
            end
            3'd1: begin
                matrix_upd[1][0] = wr_en[1];
                matrix_upd[1][2] = wr_en[1];
                matrix_upd[1][4] = wr_en[1];
                matrix_upd[1][7] = wr_en[1];
                matrix_upd[1][11] = wr_en[1];
                matrix_upd[1][16] = wr_en[1];
                matrix_upd[1][22] = wr_en[1];
            end
            3'd2: begin
                matrix_upd[1][1] = wr_en[1];
                matrix_upd[1][2] = wr_en[1];
                matrix_upd[1][5] = wr_en[1];
                matrix_upd[1][8] = wr_en[1];
                matrix_upd[1][12] = wr_en[1];
                matrix_upd[1][17] = wr_en[1];
                matrix_upd[1][23] = wr_en[1];
            end
            3'd3: begin
                matrix_upd[1][3] = wr_en[1];
                matrix_upd[1][4] = wr_en[1];
                matrix_upd[1][5] = wr_en[1];
                matrix_upd[1][9] = wr_en[1];
                matrix_upd[1][13] = wr_en[1];
                matrix_upd[1][18] = wr_en[1];
                matrix_upd[1][24] = wr_en[1];
            end
            3'd4: begin
                matrix_upd[1][6] = wr_en[1];
                matrix_upd[1][7] = wr_en[1];
                matrix_upd[1][8] = wr_en[1];
                matrix_upd[1][9] = wr_en[1];
                matrix_upd[1][14] = wr_en[1];
                matrix_upd[1][19] = wr_en[1];
                matrix_upd[1][25] = wr_en[1];
            end
            3'd5: begin
                matrix_upd[1][10] = wr_en[1];
                matrix_upd[1][11] = wr_en[1];
                matrix_upd[1][12] = wr_en[1];
                matrix_upd[1][13] = wr_en[1];
                matrix_upd[1][14] = wr_en[1];
                matrix_upd[1][20] = wr_en[1];
                matrix_upd[1][26] = wr_en[1];
            end
            3'd6: begin
                matrix_upd[1][15] = wr_en[1];
                matrix_upd[1][16] = wr_en[1];
                matrix_upd[1][17] = wr_en[1];
                matrix_upd[1][18] = wr_en[1];
                matrix_upd[1][19] = wr_en[1];
                matrix_upd[1][20] = wr_en[1];
                matrix_upd[1][27] = wr_en[1];
            end
            3'd7: begin
                matrix_upd[1][21] = wr_en[1];
                matrix_upd[1][22] = wr_en[1];
                matrix_upd[1][23] = wr_en[1];
                matrix_upd[1][24] = wr_en[1];
                matrix_upd[1][25] = wr_en[1];
                matrix_upd[1][26] = wr_en[1];
                matrix_upd[1][27] = wr_en[1];
            end
        endcase
    end
    assign age_matri_upd = matrix_upd[0] | matrix_upd[1];
    always_comb begin
        matrix_d[0] = 28'b0;
        case (wr_id[0])
            3'd0: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][1] = write_vec[0][1];
                matrix_d[0][3] = write_vec[0][2];
                matrix_d[0][6] = write_vec[0][3];
                matrix_d[0][10] = write_vec[0][4];
                matrix_d[0][15] = write_vec[0][5];
                matrix_d[0][21] = write_vec[0][6];
            end
            3'd1: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][4] = write_vec[0][2];
                matrix_d[0][7] = write_vec[0][3];
                matrix_d[0][11] = write_vec[0][4];
                matrix_d[0][16] = write_vec[0][5];
                matrix_d[0][22] = write_vec[0][6];
            end
            3'd2: begin
                matrix_d[0][1] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
                matrix_d[0][8] = write_vec[0][3];
                matrix_d[0][12] = write_vec[0][4];
                matrix_d[0][17] = write_vec[0][5];
                matrix_d[0][23] = write_vec[0][6];
            end
            3'd3: begin
                matrix_d[0][3] = write_vec[0][0];
                matrix_d[0][4] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
                matrix_d[0][9] = write_vec[0][3];
                matrix_d[0][13] = write_vec[0][4];
                matrix_d[0][18] = write_vec[0][5];
                matrix_d[0][24] = write_vec[0][6];
            end
            3'd4: begin
                matrix_d[0][6] = write_vec[0][0];
                matrix_d[0][7] = write_vec[0][1];
                matrix_d[0][8] = write_vec[0][2];
                matrix_d[0][9] = write_vec[0][3];
                matrix_d[0][14] = write_vec[0][4];
                matrix_d[0][19] = write_vec[0][5];
                matrix_d[0][25] = write_vec[0][6];
            end
            3'd5: begin
                matrix_d[0][10] = write_vec[0][0];
                matrix_d[0][11] = write_vec[0][1];
                matrix_d[0][12] = write_vec[0][2];
                matrix_d[0][13] = write_vec[0][3];
                matrix_d[0][14] = write_vec[0][4];
                matrix_d[0][20] = write_vec[0][5];
                matrix_d[0][26] = write_vec[0][6];
            end
            3'd6: begin
                matrix_d[0][15] = write_vec[0][0];
                matrix_d[0][16] = write_vec[0][1];
                matrix_d[0][17] = write_vec[0][2];
                matrix_d[0][18] = write_vec[0][3];
                matrix_d[0][19] = write_vec[0][4];
                matrix_d[0][20] = write_vec[0][5];
                matrix_d[0][27] = write_vec[0][6];
            end
            3'd7: begin
                matrix_d[0][21] = write_vec[0][0];
                matrix_d[0][22] = write_vec[0][1];
                matrix_d[0][23] = write_vec[0][2];
                matrix_d[0][24] = write_vec[0][3];
                matrix_d[0][25] = write_vec[0][4];
                matrix_d[0][26] = write_vec[0][5];
                matrix_d[0][27] = write_vec[0][6];
            end
        endcase
    end
    always_comb begin
        matrix_d[1] = 28'b0;
        case (wr_id[1])
            3'd0: begin
                matrix_d[1][0] = write_vec[1][0];
                matrix_d[1][1] = write_vec[1][1];
                matrix_d[1][3] = write_vec[1][2];
                matrix_d[1][6] = write_vec[1][3];
                matrix_d[1][10] = write_vec[1][4];
                matrix_d[1][15] = write_vec[1][5];
                matrix_d[1][21] = write_vec[1][6];
            end
            3'd1: begin
                matrix_d[1][0] = write_vec[1][0];
                matrix_d[1][2] = write_vec[1][1];
                matrix_d[1][4] = write_vec[1][2];
                matrix_d[1][7] = write_vec[1][3];
                matrix_d[1][11] = write_vec[1][4];
                matrix_d[1][16] = write_vec[1][5];
                matrix_d[1][22] = write_vec[1][6];
            end
            3'd2: begin
                matrix_d[1][1] = write_vec[1][0];
                matrix_d[1][2] = write_vec[1][1];
                matrix_d[1][5] = write_vec[1][2];
                matrix_d[1][8] = write_vec[1][3];
                matrix_d[1][12] = write_vec[1][4];
                matrix_d[1][17] = write_vec[1][5];
                matrix_d[1][23] = write_vec[1][6];
            end
            3'd3: begin
                matrix_d[1][3] = write_vec[1][0];
                matrix_d[1][4] = write_vec[1][1];
                matrix_d[1][5] = write_vec[1][2];
                matrix_d[1][9] = write_vec[1][3];
                matrix_d[1][13] = write_vec[1][4];
                matrix_d[1][18] = write_vec[1][5];
                matrix_d[1][24] = write_vec[1][6];
            end
            3'd4: begin
                matrix_d[1][6] = write_vec[1][0];
                matrix_d[1][7] = write_vec[1][1];
                matrix_d[1][8] = write_vec[1][2];
                matrix_d[1][9] = write_vec[1][3];
                matrix_d[1][14] = write_vec[1][4];
                matrix_d[1][19] = write_vec[1][5];
                matrix_d[1][25] = write_vec[1][6];
            end
            3'd5: begin
                matrix_d[1][10] = write_vec[1][0];
                matrix_d[1][11] = write_vec[1][1];
                matrix_d[1][12] = write_vec[1][2];
                matrix_d[1][13] = write_vec[1][3];
                matrix_d[1][14] = write_vec[1][4];
                matrix_d[1][20] = write_vec[1][5];
                matrix_d[1][26] = write_vec[1][6];
            end
            3'd6: begin
                matrix_d[1][15] = write_vec[1][0];
                matrix_d[1][16] = write_vec[1][1];
                matrix_d[1][17] = write_vec[1][2];
                matrix_d[1][18] = write_vec[1][3];
                matrix_d[1][19] = write_vec[1][4];
                matrix_d[1][20] = write_vec[1][5];
                matrix_d[1][27] = write_vec[1][6];
            end
            3'd7: begin
                matrix_d[1][21] = write_vec[1][0];
                matrix_d[1][22] = write_vec[1][1];
                matrix_d[1][23] = write_vec[1][2];
                matrix_d[1][24] = write_vec[1][3];
                matrix_d[1][25] = write_vec[1][4];
                matrix_d[1][26] = write_vec[1][5];
                matrix_d[1][27] = write_vec[1][6];
            end
        endcase
    end
    assign age_matri_d[0] = matrix_upd[1][0] ? matrix_d[1][0] : matrix_d[0][0];
    assign age_matri_d[1] = matrix_upd[1][1] ? matrix_d[1][1] : matrix_d[0][1];
    assign age_matri_d[2] = matrix_upd[1][2] ? matrix_d[1][2] : matrix_d[0][2];
    assign age_matri_d[3] = matrix_upd[1][3] ? matrix_d[1][3] : matrix_d[0][3];
    assign age_matri_d[4] = matrix_upd[1][4] ? matrix_d[1][4] : matrix_d[0][4];
    assign age_matri_d[5] = matrix_upd[1][5] ? matrix_d[1][5] : matrix_d[0][5];
    assign age_matri_d[6] = matrix_upd[1][6] ? matrix_d[1][6] : matrix_d[0][6];
    assign age_matri_d[7] = matrix_upd[1][7] ? matrix_d[1][7] : matrix_d[0][7];
    assign age_matri_d[8] = matrix_upd[1][8] ? matrix_d[1][8] : matrix_d[0][8];
    assign age_matri_d[9] = matrix_upd[1][9] ? matrix_d[1][9] : matrix_d[0][9];
    assign age_matri_d[10] = matrix_upd[1][10] ? matrix_d[1][10] : matrix_d[0][10];
    assign age_matri_d[11] = matrix_upd[1][11] ? matrix_d[1][11] : matrix_d[0][11];
    assign age_matri_d[12] = matrix_upd[1][12] ? matrix_d[1][12] : matrix_d[0][12];
    assign age_matri_d[13] = matrix_upd[1][13] ? matrix_d[1][13] : matrix_d[0][13];
    assign age_matri_d[14] = matrix_upd[1][14] ? matrix_d[1][14] : matrix_d[0][14];
    assign age_matri_d[15] = matrix_upd[1][15] ? matrix_d[1][15] : matrix_d[0][15];
    assign age_matri_d[16] = matrix_upd[1][16] ? matrix_d[1][16] : matrix_d[0][16];
    assign age_matri_d[17] = matrix_upd[1][17] ? matrix_d[1][17] : matrix_d[0][17];
    assign age_matri_d[18] = matrix_upd[1][18] ? matrix_d[1][18] : matrix_d[0][18];
    assign age_matri_d[19] = matrix_upd[1][19] ? matrix_d[1][19] : matrix_d[0][19];
    assign age_matri_d[20] = matrix_upd[1][20] ? matrix_d[1][20] : matrix_d[0][20];
    assign age_matri_d[21] = matrix_upd[1][21] ? matrix_d[1][21] : matrix_d[0][21];
    assign age_matri_d[22] = matrix_upd[1][22] ? matrix_d[1][22] : matrix_d[0][22];
    assign age_matri_d[23] = matrix_upd[1][23] ? matrix_d[1][23] : matrix_d[0][23];
    assign age_matri_d[24] = matrix_upd[1][24] ? matrix_d[1][24] : matrix_d[0][24];
    assign age_matri_d[25] = matrix_upd[1][25] ? matrix_d[1][25] : matrix_d[0][25];
    assign age_matri_d[26] = matrix_upd[1][26] ? matrix_d[1][26] : matrix_d[0][26];
    assign age_matri_d[27] = matrix_upd[1][27] ? matrix_d[1][27] : matrix_d[0][27];
 
    // Raw age vectors (without valid)
    assign age_vec_raw[0][0] = ~age_matri_q[0];
    assign age_vec_raw[0][1] = ~age_matri_q[1];
    assign age_vec_raw[0][2] = ~age_matri_q[3];
    assign age_vec_raw[0][3] = ~age_matri_q[6];
    assign age_vec_raw[0][4] = ~age_matri_q[10];
    assign age_vec_raw[0][5] = ~age_matri_q[15];
    assign age_vec_raw[0][6] = ~age_matri_q[21];
    assign age_vec_raw[1][0] =  age_matri_q[0];
    assign age_vec_raw[1][1] = ~age_matri_q[2];
    assign age_vec_raw[1][2] = ~age_matri_q[4];
    assign age_vec_raw[1][3] = ~age_matri_q[7];
    assign age_vec_raw[1][4] = ~age_matri_q[11];
    assign age_vec_raw[1][5] = ~age_matri_q[16];
    assign age_vec_raw[1][6] = ~age_matri_q[22];
    assign age_vec_raw[2][0] =  age_matri_q[1];
    assign age_vec_raw[2][1] =  age_matri_q[2];
    assign age_vec_raw[2][2] = ~age_matri_q[5];
    assign age_vec_raw[2][3] = ~age_matri_q[8];
    assign age_vec_raw[2][4] = ~age_matri_q[12];
    assign age_vec_raw[2][5] = ~age_matri_q[17];
    assign age_vec_raw[2][6] = ~age_matri_q[23];
    assign age_vec_raw[3][0] =  age_matri_q[3];
    assign age_vec_raw[3][1] =  age_matri_q[4];
    assign age_vec_raw[3][2] =  age_matri_q[5];
    assign age_vec_raw[3][3] = ~age_matri_q[9];
    assign age_vec_raw[3][4] = ~age_matri_q[13];
    assign age_vec_raw[3][5] = ~age_matri_q[18];
    assign age_vec_raw[3][6] = ~age_matri_q[24];
    assign age_vec_raw[4][0] =  age_matri_q[6];
    assign age_vec_raw[4][1] =  age_matri_q[7];
    assign age_vec_raw[4][2] =  age_matri_q[8];
    assign age_vec_raw[4][3] =  age_matri_q[9];
    assign age_vec_raw[4][4] = ~age_matri_q[14];
    assign age_vec_raw[4][5] = ~age_matri_q[19];
    assign age_vec_raw[4][6] = ~age_matri_q[25];
    assign age_vec_raw[5][0] =  age_matri_q[10];
    assign age_vec_raw[5][1] =  age_matri_q[11];
    assign age_vec_raw[5][2] =  age_matri_q[12];
    assign age_vec_raw[5][3] =  age_matri_q[13];
    assign age_vec_raw[5][4] =  age_matri_q[14];
    assign age_vec_raw[5][5] = ~age_matri_q[20];
    assign age_vec_raw[5][6] = ~age_matri_q[26];
    assign age_vec_raw[6][0] =  age_matri_q[15];
    assign age_vec_raw[6][1] =  age_matri_q[16];
    assign age_vec_raw[6][2] =  age_matri_q[17];
    assign age_vec_raw[6][3] =  age_matri_q[18];
    assign age_vec_raw[6][4] =  age_matri_q[19];
    assign age_vec_raw[6][5] =  age_matri_q[20];
    assign age_vec_raw[6][6] = ~age_matri_q[27];
    assign age_vec_raw[7][0] =  age_matri_q[21];
    assign age_vec_raw[7][1] =  age_matri_q[22];
    assign age_vec_raw[7][2] =  age_matri_q[23];
    assign age_vec_raw[7][3] =  age_matri_q[24];
    assign age_vec_raw[7][4] =  age_matri_q[25];
    assign age_vec_raw[7][5] =  age_matri_q[26];
    assign age_vec_raw[7][6] =  age_matri_q[27];
 
    // Generate age vectors on the basis of valid vector
if(FIND_OLDEST==1)  begin: age_matrix_gen_8_2_2_1_4_1_oldest_agev_gen
    assign age_vec[0][0][0] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[0][0][1] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[0][0][2] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[0][0][3] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[0][3]);
    assign age_vec[0][0][4] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[0][4]);
    assign age_vec[0][0][5] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][6] ? 1'b0 : age_vec_raw[0][5]);
    assign age_vec[0][0][6] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][7] ? 1'b0 : age_vec_raw[0][6]);
    assign age_vec[0][1][0] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[0][1][1] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[0][1][2] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[0][1][3] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[1][3]);
    assign age_vec[0][1][4] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[1][4]);
    assign age_vec[0][1][5] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][6] ? 1'b0 : age_vec_raw[1][5]);
    assign age_vec[0][1][6] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][7] ? 1'b0 : age_vec_raw[1][6]);
    assign age_vec[0][2][0] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[0][2][1] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[0][2][2] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[0][2][3] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[2][3]);
    assign age_vec[0][2][4] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[2][4]);
    assign age_vec[0][2][5] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][6] ? 1'b0 : age_vec_raw[2][5]);
    assign age_vec[0][2][6] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][7] ? 1'b0 : age_vec_raw[2][6]);
    assign age_vec[0][3][0] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[0][3][1] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[0][3][2] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[0][3][3] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[3][3]);
    assign age_vec[0][3][4] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[3][4]);
    assign age_vec[0][3][5] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][6] ? 1'b0 : age_vec_raw[3][5]);
    assign age_vec[0][3][6] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][7] ? 1'b0 : age_vec_raw[3][6]);
    assign age_vec[0][4][0] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[4][0]);
    assign age_vec[0][4][1] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[4][1]);
    assign age_vec[0][4][2] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[4][2]);
    assign age_vec[0][4][3] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[4][3]);
    assign age_vec[0][4][4] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[4][4]);
    assign age_vec[0][4][5] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][6] ? 1'b0 : age_vec_raw[4][5]);
    assign age_vec[0][4][6] = !oldest_vld_vec[0][4] ? 1'b1 : (!oldest_vld_vec[0][7] ? 1'b0 : age_vec_raw[4][6]);
    assign age_vec[0][5][0] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[5][0]);
    assign age_vec[0][5][1] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[5][1]);
    assign age_vec[0][5][2] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[5][2]);
    assign age_vec[0][5][3] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[5][3]);
    assign age_vec[0][5][4] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[5][4]);
    assign age_vec[0][5][5] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][6] ? 1'b0 : age_vec_raw[5][5]);
    assign age_vec[0][5][6] = !oldest_vld_vec[0][5] ? 1'b1 : (!oldest_vld_vec[0][7] ? 1'b0 : age_vec_raw[5][6]);
    assign age_vec[0][6][0] = !oldest_vld_vec[0][6] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[6][0]);
    assign age_vec[0][6][1] = !oldest_vld_vec[0][6] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[6][1]);
    assign age_vec[0][6][2] = !oldest_vld_vec[0][6] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[6][2]);
    assign age_vec[0][6][3] = !oldest_vld_vec[0][6] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[6][3]);
    assign age_vec[0][6][4] = !oldest_vld_vec[0][6] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[6][4]);
    assign age_vec[0][6][5] = !oldest_vld_vec[0][6] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[6][5]);
    assign age_vec[0][6][6] = !oldest_vld_vec[0][6] ? 1'b1 : (!oldest_vld_vec[0][7] ? 1'b0 : age_vec_raw[6][6]);
    assign age_vec[0][7][0] = !oldest_vld_vec[0][7] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[7][0]);
    assign age_vec[0][7][1] = !oldest_vld_vec[0][7] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[7][1]);
    assign age_vec[0][7][2] = !oldest_vld_vec[0][7] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[7][2]);
    assign age_vec[0][7][3] = !oldest_vld_vec[0][7] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[7][3]);
    assign age_vec[0][7][4] = !oldest_vld_vec[0][7] ? 1'b1 : (!oldest_vld_vec[0][4] ? 1'b0 : age_vec_raw[7][4]);
    assign age_vec[0][7][5] = !oldest_vld_vec[0][7] ? 1'b1 : (!oldest_vld_vec[0][5] ? 1'b0 : age_vec_raw[7][5]);
    assign age_vec[0][7][6] = !oldest_vld_vec[0][7] ? 1'b1 : (!oldest_vld_vec[0][6] ? 1'b0 : age_vec_raw[7][6]);
    assign age_vec[1][0][0] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[1][0][1] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[1][0][2] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[1][0][3] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[0][3]);
    assign age_vec[1][0][4] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[0][4]);
    assign age_vec[1][0][5] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][6] ? 1'b0 : age_vec_raw[0][5]);
    assign age_vec[1][0][6] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][7] ? 1'b0 : age_vec_raw[0][6]);
    assign age_vec[1][1][0] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[1][1][1] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[1][1][2] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[1][1][3] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[1][3]);
    assign age_vec[1][1][4] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[1][4]);
    assign age_vec[1][1][5] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][6] ? 1'b0 : age_vec_raw[1][5]);
    assign age_vec[1][1][6] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][7] ? 1'b0 : age_vec_raw[1][6]);
    assign age_vec[1][2][0] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[1][2][1] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[1][2][2] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[1][2][3] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[2][3]);
    assign age_vec[1][2][4] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[2][4]);
    assign age_vec[1][2][5] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][6] ? 1'b0 : age_vec_raw[2][5]);
    assign age_vec[1][2][6] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][7] ? 1'b0 : age_vec_raw[2][6]);
    assign age_vec[1][3][0] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[1][3][1] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[1][3][2] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[1][3][3] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[3][3]);
    assign age_vec[1][3][4] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[3][4]);
    assign age_vec[1][3][5] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][6] ? 1'b0 : age_vec_raw[3][5]);
    assign age_vec[1][3][6] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][7] ? 1'b0 : age_vec_raw[3][6]);
    assign age_vec[1][4][0] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[4][0]);
    assign age_vec[1][4][1] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[4][1]);
    assign age_vec[1][4][2] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[4][2]);
    assign age_vec[1][4][3] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[4][3]);
    assign age_vec[1][4][4] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[4][4]);
    assign age_vec[1][4][5] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][6] ? 1'b0 : age_vec_raw[4][5]);
    assign age_vec[1][4][6] = !oldest_vld_vec[1][4] ? 1'b1 : (!oldest_vld_vec[1][7] ? 1'b0 : age_vec_raw[4][6]);
    assign age_vec[1][5][0] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[5][0]);
    assign age_vec[1][5][1] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[5][1]);
    assign age_vec[1][5][2] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[5][2]);
    assign age_vec[1][5][3] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[5][3]);
    assign age_vec[1][5][4] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[5][4]);
    assign age_vec[1][5][5] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][6] ? 1'b0 : age_vec_raw[5][5]);
    assign age_vec[1][5][6] = !oldest_vld_vec[1][5] ? 1'b1 : (!oldest_vld_vec[1][7] ? 1'b0 : age_vec_raw[5][6]);
    assign age_vec[1][6][0] = !oldest_vld_vec[1][6] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[6][0]);
    assign age_vec[1][6][1] = !oldest_vld_vec[1][6] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[6][1]);
    assign age_vec[1][6][2] = !oldest_vld_vec[1][6] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[6][2]);
    assign age_vec[1][6][3] = !oldest_vld_vec[1][6] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[6][3]);
    assign age_vec[1][6][4] = !oldest_vld_vec[1][6] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[6][4]);
    assign age_vec[1][6][5] = !oldest_vld_vec[1][6] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[6][5]);
    assign age_vec[1][6][6] = !oldest_vld_vec[1][6] ? 1'b1 : (!oldest_vld_vec[1][7] ? 1'b0 : age_vec_raw[6][6]);
    assign age_vec[1][7][0] = !oldest_vld_vec[1][7] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[7][0]);
    assign age_vec[1][7][1] = !oldest_vld_vec[1][7] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[7][1]);
    assign age_vec[1][7][2] = !oldest_vld_vec[1][7] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[7][2]);
    assign age_vec[1][7][3] = !oldest_vld_vec[1][7] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[7][3]);
    assign age_vec[1][7][4] = !oldest_vld_vec[1][7] ? 1'b1 : (!oldest_vld_vec[1][4] ? 1'b0 : age_vec_raw[7][4]);
    assign age_vec[1][7][5] = !oldest_vld_vec[1][7] ? 1'b1 : (!oldest_vld_vec[1][5] ? 1'b0 : age_vec_raw[7][5]);
    assign age_vec[1][7][6] = !oldest_vld_vec[1][7] ? 1'b1 : (!oldest_vld_vec[1][6] ? 1'b0 : age_vec_raw[7][6]);
    assign age_vec[2][0][0] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[2][0][1] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[2][0][2] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[2][0][3] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[0][3]);
    assign age_vec[2][0][4] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[0][4]);
    assign age_vec[2][0][5] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][6] ? 1'b0 : age_vec_raw[0][5]);
    assign age_vec[2][0][6] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][7] ? 1'b0 : age_vec_raw[0][6]);
    assign age_vec[2][1][0] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[2][1][1] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[2][1][2] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[2][1][3] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[1][3]);
    assign age_vec[2][1][4] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[1][4]);
    assign age_vec[2][1][5] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][6] ? 1'b0 : age_vec_raw[1][5]);
    assign age_vec[2][1][6] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][7] ? 1'b0 : age_vec_raw[1][6]);
    assign age_vec[2][2][0] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[2][2][1] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[2][2][2] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[2][2][3] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[2][3]);
    assign age_vec[2][2][4] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[2][4]);
    assign age_vec[2][2][5] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][6] ? 1'b0 : age_vec_raw[2][5]);
    assign age_vec[2][2][6] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][7] ? 1'b0 : age_vec_raw[2][6]);
    assign age_vec[2][3][0] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[2][3][1] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[2][3][2] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[2][3][3] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[3][3]);
    assign age_vec[2][3][4] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[3][4]);
    assign age_vec[2][3][5] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][6] ? 1'b0 : age_vec_raw[3][5]);
    assign age_vec[2][3][6] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][7] ? 1'b0 : age_vec_raw[3][6]);
    assign age_vec[2][4][0] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[4][0]);
    assign age_vec[2][4][1] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[4][1]);
    assign age_vec[2][4][2] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[4][2]);
    assign age_vec[2][4][3] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[4][3]);
    assign age_vec[2][4][4] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[4][4]);
    assign age_vec[2][4][5] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][6] ? 1'b0 : age_vec_raw[4][5]);
    assign age_vec[2][4][6] = !oldest_vld_vec[2][4] ? 1'b1 : (!oldest_vld_vec[2][7] ? 1'b0 : age_vec_raw[4][6]);
    assign age_vec[2][5][0] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[5][0]);
    assign age_vec[2][5][1] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[5][1]);
    assign age_vec[2][5][2] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[5][2]);
    assign age_vec[2][5][3] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[5][3]);
    assign age_vec[2][5][4] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[5][4]);
    assign age_vec[2][5][5] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][6] ? 1'b0 : age_vec_raw[5][5]);
    assign age_vec[2][5][6] = !oldest_vld_vec[2][5] ? 1'b1 : (!oldest_vld_vec[2][7] ? 1'b0 : age_vec_raw[5][6]);
    assign age_vec[2][6][0] = !oldest_vld_vec[2][6] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[6][0]);
    assign age_vec[2][6][1] = !oldest_vld_vec[2][6] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[6][1]);
    assign age_vec[2][6][2] = !oldest_vld_vec[2][6] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[6][2]);
    assign age_vec[2][6][3] = !oldest_vld_vec[2][6] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[6][3]);
    assign age_vec[2][6][4] = !oldest_vld_vec[2][6] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[6][4]);
    assign age_vec[2][6][5] = !oldest_vld_vec[2][6] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[6][5]);
    assign age_vec[2][6][6] = !oldest_vld_vec[2][6] ? 1'b1 : (!oldest_vld_vec[2][7] ? 1'b0 : age_vec_raw[6][6]);
    assign age_vec[2][7][0] = !oldest_vld_vec[2][7] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[7][0]);
    assign age_vec[2][7][1] = !oldest_vld_vec[2][7] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[7][1]);
    assign age_vec[2][7][2] = !oldest_vld_vec[2][7] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[7][2]);
    assign age_vec[2][7][3] = !oldest_vld_vec[2][7] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[7][3]);
    assign age_vec[2][7][4] = !oldest_vld_vec[2][7] ? 1'b1 : (!oldest_vld_vec[2][4] ? 1'b0 : age_vec_raw[7][4]);
    assign age_vec[2][7][5] = !oldest_vld_vec[2][7] ? 1'b1 : (!oldest_vld_vec[2][5] ? 1'b0 : age_vec_raw[7][5]);
    assign age_vec[2][7][6] = !oldest_vld_vec[2][7] ? 1'b1 : (!oldest_vld_vec[2][6] ? 1'b0 : age_vec_raw[7][6]);
    assign age_vec[3][0][0] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[3][0][1] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[3][0][2] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[3][0][3] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][4] ? 1'b0 : age_vec_raw[0][3]);
    assign age_vec[3][0][4] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][5] ? 1'b0 : age_vec_raw[0][4]);
    assign age_vec[3][0][5] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][6] ? 1'b0 : age_vec_raw[0][5]);
    assign age_vec[3][0][6] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][7] ? 1'b0 : age_vec_raw[0][6]);
    assign age_vec[3][1][0] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[3][1][1] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[3][1][2] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[3][1][3] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][4] ? 1'b0 : age_vec_raw[1][3]);
    assign age_vec[3][1][4] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][5] ? 1'b0 : age_vec_raw[1][4]);
    assign age_vec[3][1][5] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][6] ? 1'b0 : age_vec_raw[1][5]);
    assign age_vec[3][1][6] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][7] ? 1'b0 : age_vec_raw[1][6]);
    assign age_vec[3][2][0] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[3][2][1] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[3][2][2] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[3][2][3] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][4] ? 1'b0 : age_vec_raw[2][3]);
    assign age_vec[3][2][4] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][5] ? 1'b0 : age_vec_raw[2][4]);
    assign age_vec[3][2][5] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][6] ? 1'b0 : age_vec_raw[2][5]);
    assign age_vec[3][2][6] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][7] ? 1'b0 : age_vec_raw[2][6]);
    assign age_vec[3][3][0] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[3][3][1] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[3][3][2] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[3][3][3] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][4] ? 1'b0 : age_vec_raw[3][3]);
    assign age_vec[3][3][4] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][5] ? 1'b0 : age_vec_raw[3][4]);
    assign age_vec[3][3][5] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][6] ? 1'b0 : age_vec_raw[3][5]);
    assign age_vec[3][3][6] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][7] ? 1'b0 : age_vec_raw[3][6]);
    assign age_vec[3][4][0] = !oldest_vld_vec[3][4] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[4][0]);
    assign age_vec[3][4][1] = !oldest_vld_vec[3][4] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[4][1]);
    assign age_vec[3][4][2] = !oldest_vld_vec[3][4] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[4][2]);
    assign age_vec[3][4][3] = !oldest_vld_vec[3][4] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[4][3]);
    assign age_vec[3][4][4] = !oldest_vld_vec[3][4] ? 1'b1 : (!oldest_vld_vec[3][5] ? 1'b0 : age_vec_raw[4][4]);
    assign age_vec[3][4][5] = !oldest_vld_vec[3][4] ? 1'b1 : (!oldest_vld_vec[3][6] ? 1'b0 : age_vec_raw[4][5]);
    assign age_vec[3][4][6] = !oldest_vld_vec[3][4] ? 1'b1 : (!oldest_vld_vec[3][7] ? 1'b0 : age_vec_raw[4][6]);
    assign age_vec[3][5][0] = !oldest_vld_vec[3][5] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[5][0]);
    assign age_vec[3][5][1] = !oldest_vld_vec[3][5] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[5][1]);
    assign age_vec[3][5][2] = !oldest_vld_vec[3][5] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[5][2]);
    assign age_vec[3][5][3] = !oldest_vld_vec[3][5] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[5][3]);
    assign age_vec[3][5][4] = !oldest_vld_vec[3][5] ? 1'b1 : (!oldest_vld_vec[3][4] ? 1'b0 : age_vec_raw[5][4]);
    assign age_vec[3][5][5] = !oldest_vld_vec[3][5] ? 1'b1 : (!oldest_vld_vec[3][6] ? 1'b0 : age_vec_raw[5][5]);
    assign age_vec[3][5][6] = !oldest_vld_vec[3][5] ? 1'b1 : (!oldest_vld_vec[3][7] ? 1'b0 : age_vec_raw[5][6]);
    assign age_vec[3][6][0] = !oldest_vld_vec[3][6] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[6][0]);
    assign age_vec[3][6][1] = !oldest_vld_vec[3][6] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[6][1]);
    assign age_vec[3][6][2] = !oldest_vld_vec[3][6] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[6][2]);
    assign age_vec[3][6][3] = !oldest_vld_vec[3][6] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[6][3]);
    assign age_vec[3][6][4] = !oldest_vld_vec[3][6] ? 1'b1 : (!oldest_vld_vec[3][4] ? 1'b0 : age_vec_raw[6][4]);
    assign age_vec[3][6][5] = !oldest_vld_vec[3][6] ? 1'b1 : (!oldest_vld_vec[3][5] ? 1'b0 : age_vec_raw[6][5]);
    assign age_vec[3][6][6] = !oldest_vld_vec[3][6] ? 1'b1 : (!oldest_vld_vec[3][7] ? 1'b0 : age_vec_raw[6][6]);
    assign age_vec[3][7][0] = !oldest_vld_vec[3][7] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[7][0]);
    assign age_vec[3][7][1] = !oldest_vld_vec[3][7] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[7][1]);
    assign age_vec[3][7][2] = !oldest_vld_vec[3][7] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[7][2]);
    assign age_vec[3][7][3] = !oldest_vld_vec[3][7] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[7][3]);
    assign age_vec[3][7][4] = !oldest_vld_vec[3][7] ? 1'b1 : (!oldest_vld_vec[3][4] ? 1'b0 : age_vec_raw[7][4]);
    assign age_vec[3][7][5] = !oldest_vld_vec[3][7] ? 1'b1 : (!oldest_vld_vec[3][5] ? 1'b0 : age_vec_raw[7][5]);
    assign age_vec[3][7][6] = !oldest_vld_vec[3][7] ? 1'b1 : (!oldest_vld_vec[3][6] ? 1'b0 : age_vec_raw[7][6]);
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_8_2_2_1_4_1_newest_agev_gen
    assign age_vec_n[0][0][0] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[0][0]);
    assign age_vec_n[0][0][1] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[0][1]);
    assign age_vec_n[0][0][2] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[0][2]);
    assign age_vec_n[0][0][3] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[0][3]);
    assign age_vec_n[0][0][4] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[0][4]);
    assign age_vec_n[0][0][5] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][6] ? 1'b0 : ~age_vec_raw[0][5]);
    assign age_vec_n[0][0][6] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][7] ? 1'b0 : ~age_vec_raw[0][6]);
    assign age_vec_n[0][1][0] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[1][0]);
    assign age_vec_n[0][1][1] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[1][1]);
    assign age_vec_n[0][1][2] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[1][2]);
    assign age_vec_n[0][1][3] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[1][3]);
    assign age_vec_n[0][1][4] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[1][4]);
    assign age_vec_n[0][1][5] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][6] ? 1'b0 : ~age_vec_raw[1][5]);
    assign age_vec_n[0][1][6] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][7] ? 1'b0 : ~age_vec_raw[1][6]);
    assign age_vec_n[0][2][0] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[2][0]);
    assign age_vec_n[0][2][1] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[2][1]);
    assign age_vec_n[0][2][2] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[2][2]);
    assign age_vec_n[0][2][3] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[2][3]);
    assign age_vec_n[0][2][4] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[2][4]);
    assign age_vec_n[0][2][5] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][6] ? 1'b0 : ~age_vec_raw[2][5]);
    assign age_vec_n[0][2][6] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][7] ? 1'b0 : ~age_vec_raw[2][6]);
    assign age_vec_n[0][3][0] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[3][0]);
    assign age_vec_n[0][3][1] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[3][1]);
    assign age_vec_n[0][3][2] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[3][2]);
    assign age_vec_n[0][3][3] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[3][3]);
    assign age_vec_n[0][3][4] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[3][4]);
    assign age_vec_n[0][3][5] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][6] ? 1'b0 : ~age_vec_raw[3][5]);
    assign age_vec_n[0][3][6] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][7] ? 1'b0 : ~age_vec_raw[3][6]);
    assign age_vec_n[0][4][0] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[4][0]);
    assign age_vec_n[0][4][1] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[4][1]);
    assign age_vec_n[0][4][2] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[4][2]);
    assign age_vec_n[0][4][3] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[4][3]);
    assign age_vec_n[0][4][4] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[4][4]);
    assign age_vec_n[0][4][5] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][6] ? 1'b0 : ~age_vec_raw[4][5]);
    assign age_vec_n[0][4][6] = !newest_vld_vec[0][4] ? 1'b1 : (!newest_vld_vec[0][7] ? 1'b0 : ~age_vec_raw[4][6]);
    assign age_vec_n[0][5][0] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[5][0]);
    assign age_vec_n[0][5][1] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[5][1]);
    assign age_vec_n[0][5][2] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[5][2]);
    assign age_vec_n[0][5][3] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[5][3]);
    assign age_vec_n[0][5][4] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[5][4]);
    assign age_vec_n[0][5][5] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][6] ? 1'b0 : ~age_vec_raw[5][5]);
    assign age_vec_n[0][5][6] = !newest_vld_vec[0][5] ? 1'b1 : (!newest_vld_vec[0][7] ? 1'b0 : ~age_vec_raw[5][6]);
    assign age_vec_n[0][6][0] = !newest_vld_vec[0][6] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[6][0]);
    assign age_vec_n[0][6][1] = !newest_vld_vec[0][6] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[6][1]);
    assign age_vec_n[0][6][2] = !newest_vld_vec[0][6] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[6][2]);
    assign age_vec_n[0][6][3] = !newest_vld_vec[0][6] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[6][3]);
    assign age_vec_n[0][6][4] = !newest_vld_vec[0][6] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[6][4]);
    assign age_vec_n[0][6][5] = !newest_vld_vec[0][6] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[6][5]);
    assign age_vec_n[0][6][6] = !newest_vld_vec[0][6] ? 1'b1 : (!newest_vld_vec[0][7] ? 1'b0 : ~age_vec_raw[6][6]);
    assign age_vec_n[0][7][0] = !newest_vld_vec[0][7] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[7][0]);
    assign age_vec_n[0][7][1] = !newest_vld_vec[0][7] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[7][1]);
    assign age_vec_n[0][7][2] = !newest_vld_vec[0][7] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[7][2]);
    assign age_vec_n[0][7][3] = !newest_vld_vec[0][7] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[7][3]);
    assign age_vec_n[0][7][4] = !newest_vld_vec[0][7] ? 1'b1 : (!newest_vld_vec[0][4] ? 1'b0 : ~age_vec_raw[7][4]);
    assign age_vec_n[0][7][5] = !newest_vld_vec[0][7] ? 1'b1 : (!newest_vld_vec[0][5] ? 1'b0 : ~age_vec_raw[7][5]);
    assign age_vec_n[0][7][6] = !newest_vld_vec[0][7] ? 1'b1 : (!newest_vld_vec[0][6] ? 1'b0 : ~age_vec_raw[7][6]);
end
if(FIND_OLDEST==1)  begin: age_matrix_gen_8_2_2_1_4_1_oldest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u0_0 (
        .data(age_vec[0][0]),
        .cnt_oh(cnt_oh[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u1_0 (
        .data(age_vec[0][1]),
        .cnt_oh(cnt_oh[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u2_0 (
        .data(age_vec[0][2]),
        .cnt_oh(cnt_oh[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u3_0 (
        .data(age_vec[0][3]),
        .cnt_oh(cnt_oh[0][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u4_0 (
        .data(age_vec[0][4]),
        .cnt_oh(cnt_oh[0][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u5_0 (
        .data(age_vec[0][5]),
        .cnt_oh(cnt_oh[0][5])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u6_0 (
        .data(age_vec[0][6]),
        .cnt_oh(cnt_oh[0][6])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u7_0 (
        .data(age_vec[0][7]),
        .cnt_oh(cnt_oh[0][7])
    );
    assign oldest_rd_oh[0][0] = {cnt_oh[0][7][0], cnt_oh[0][6][0], cnt_oh[0][5][0], cnt_oh[0][4][0], cnt_oh[0][3][0], cnt_oh[0][2][0], cnt_oh[0][1][0], cnt_oh[0][0][0]};
    assign oldest_rd_oh[0][1] = {cnt_oh[0][7][1], cnt_oh[0][6][1], cnt_oh[0][5][1], cnt_oh[0][4][1], cnt_oh[0][3][1], cnt_oh[0][2][1], cnt_oh[0][1][1], cnt_oh[0][0][1]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u0_1 (
        .data(age_vec[1][0]),
        .cnt_oh(cnt_oh[1][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u1_1 (
        .data(age_vec[1][1]),
        .cnt_oh(cnt_oh[1][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u2_1 (
        .data(age_vec[1][2]),
        .cnt_oh(cnt_oh[1][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u3_1 (
        .data(age_vec[1][3]),
        .cnt_oh(cnt_oh[1][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u4_1 (
        .data(age_vec[1][4]),
        .cnt_oh(cnt_oh[1][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u5_1 (
        .data(age_vec[1][5]),
        .cnt_oh(cnt_oh[1][5])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u6_1 (
        .data(age_vec[1][6]),
        .cnt_oh(cnt_oh[1][6])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u7_1 (
        .data(age_vec[1][7]),
        .cnt_oh(cnt_oh[1][7])
    );
    assign oldest_rd_oh[1][0] = {cnt_oh[1][7][0], cnt_oh[1][6][0], cnt_oh[1][5][0], cnt_oh[1][4][0], cnt_oh[1][3][0], cnt_oh[1][2][0], cnt_oh[1][1][0], cnt_oh[1][0][0]};
    assign oldest_rd_oh[1][1] = {cnt_oh[1][7][1], cnt_oh[1][6][1], cnt_oh[1][5][1], cnt_oh[1][4][1], cnt_oh[1][3][1], cnt_oh[1][2][1], cnt_oh[1][1][1], cnt_oh[1][0][1]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u0_2 (
        .data(age_vec[2][0]),
        .cnt_oh(cnt_oh[2][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u1_2 (
        .data(age_vec[2][1]),
        .cnt_oh(cnt_oh[2][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u2_2 (
        .data(age_vec[2][2]),
        .cnt_oh(cnt_oh[2][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u3_2 (
        .data(age_vec[2][3]),
        .cnt_oh(cnt_oh[2][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u4_2 (
        .data(age_vec[2][4]),
        .cnt_oh(cnt_oh[2][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u5_2 (
        .data(age_vec[2][5]),
        .cnt_oh(cnt_oh[2][5])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u6_2 (
        .data(age_vec[2][6]),
        .cnt_oh(cnt_oh[2][6])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u7_2 (
        .data(age_vec[2][7]),
        .cnt_oh(cnt_oh[2][7])
    );
    assign oldest_rd_oh[2][0] = {cnt_oh[2][7][0], cnt_oh[2][6][0], cnt_oh[2][5][0], cnt_oh[2][4][0], cnt_oh[2][3][0], cnt_oh[2][2][0], cnt_oh[2][1][0], cnt_oh[2][0][0]};
    assign oldest_rd_oh[2][1] = {cnt_oh[2][7][1], cnt_oh[2][6][1], cnt_oh[2][5][1], cnt_oh[2][4][1], cnt_oh[2][3][1], cnt_oh[2][2][1], cnt_oh[2][1][1], cnt_oh[2][0][1]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u0_3 (
        .data(age_vec[3][0]),
        .cnt_oh(cnt_oh[3][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u1_3 (
        .data(age_vec[3][1]),
        .cnt_oh(cnt_oh[3][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u2_3 (
        .data(age_vec[3][2]),
        .cnt_oh(cnt_oh[3][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u3_3 (
        .data(age_vec[3][3]),
        .cnt_oh(cnt_oh[3][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u4_3 (
        .data(age_vec[3][4]),
        .cnt_oh(cnt_oh[3][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u5_3 (
        .data(age_vec[3][5]),
        .cnt_oh(cnt_oh[3][5])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u6_3 (
        .data(age_vec[3][6]),
        .cnt_oh(cnt_oh[3][6])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(1)
    ) wing_cbb_prefix_counter_7_1_u7_3 (
        .data(age_vec[3][7]),
        .cnt_oh(cnt_oh[3][7])
    );
    assign oldest_rd_oh[3][0] = {cnt_oh[3][7][0], cnt_oh[3][6][0], cnt_oh[3][5][0], cnt_oh[3][4][0], cnt_oh[3][3][0], cnt_oh[3][2][0], cnt_oh[3][1][0], cnt_oh[3][0][0]};
    assign oldest_rd_oh[3][1] = {cnt_oh[3][7][1], cnt_oh[3][6][1], cnt_oh[3][5][1], cnt_oh[3][4][1], cnt_oh[3][3][1], cnt_oh[3][2][1], cnt_oh[3][1][1], cnt_oh[3][0][1]};
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_8_2_2_1_4_1_newest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_7_0_u0_0 (
        .data(age_vec_n[0][0]),
        .cnt_oh(cnt_oh_n[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_7_0_u1_0 (
        .data(age_vec_n[0][1]),
        .cnt_oh(cnt_oh_n[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_7_0_u2_0 (
        .data(age_vec_n[0][2]),
        .cnt_oh(cnt_oh_n[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_7_0_u3_0 (
        .data(age_vec_n[0][3]),
        .cnt_oh(cnt_oh_n[0][3])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_7_0_u4_0 (
        .data(age_vec_n[0][4]),
        .cnt_oh(cnt_oh_n[0][4])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_7_0_u5_0 (
        .data(age_vec_n[0][5]),
        .cnt_oh(cnt_oh_n[0][5])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_7_0_u6_0 (
        .data(age_vec_n[0][6]),
        .cnt_oh(cnt_oh_n[0][6])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(7),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_7_0_u7_0 (
        .data(age_vec_n[0][7]),
        .cnt_oh(cnt_oh_n[0][7])
    );
    assign newest_rd_oh[0][0] = {cnt_oh_n[0][7][0], cnt_oh_n[0][6][0], cnt_oh_n[0][5][0], cnt_oh_n[0][4][0], cnt_oh_n[0][3][0], cnt_oh_n[0][2][0], cnt_oh_n[0][1][0], cnt_oh_n[0][0][0]};
end
if(FIND_OLDEST==0)  begin: age_matrix_gen_8_2_2_1_4_1_no_oldest
    assign age_vec = 'b0;
    assign cnt_oh = 'b0;
    assign oldest_rd_oh = 'b0;
end
if(FIND_NEWEST==0)  begin: age_matrix_gen_8_2_2_1_4_1_no_newest
    assign age_vec_n = 'b0;
    assign cnt_oh_n = 'b0;
    assign newest_rd_oh = 'b0;
end
end
if(ENTRY_NUM == 4 && WR_NUM == 1 && RD_NUM_OLD == 1 && RD_NUM_NEW == 1 && VLD_VEC_NUM_OLD == 4 && VLD_VEC_NUM_NEW == 1) begin : age_matrix_gen_4_1_1_1_4_1
    logic [0:0][2:0] write_vec_raw;
    logic [0:0][2:0] write_vec;
    logic [0:0][5:0]matrix_upd;
    logic [0:0][5:0]matrix_d;
    logic [5:0]     age_matri_q, age_matri_d, age_matri_upd;
    logic [3:0][2:0] age_vec_raw;
    logic [3:0][3:0][2:0] age_vec;
    logic [3:0][3:0][0:0] cnt_oh;
    logic [0:0][3:0][2:0] age_vec_n;
    logic [0:0][3:0][0:0] cnt_oh_n;
    // Write Vecs
    assign write_vec_raw[0] = 3'b111;
    always_comb begin
        case (wr_id[0])
            2'd0: write_vec[0][2:0] = ~write_vec_raw[0][2:0];
            2'd1: write_vec[0][2:0] = {~write_vec_raw[0][2:1], write_vec_raw[0][0:0]};
            2'd2: write_vec[0][2:0] = {~write_vec_raw[0][2:2], write_vec_raw[0][1:0]};
            2'd3: write_vec[0][2:0] =  write_vec_raw[0][2:0];
            default: write_vec[0][2:0] = 3'bx;
        endcase
    end
    // Age Matrix Reg
    `WDFFER(age_matri_q[0], age_matri_d[0], age_matri_upd[0], clk, rst_n)
    `WDFFER(age_matri_q[1], age_matri_d[1], age_matri_upd[1], clk, rst_n)
    `WDFFER(age_matri_q[2], age_matri_d[2], age_matri_upd[2], clk, rst_n)
    `WDFFER(age_matri_q[3], age_matri_d[3], age_matri_upd[3], clk, rst_n)
    `WDFFER(age_matri_q[4], age_matri_d[4], age_matri_upd[4], clk, rst_n)
    `WDFFER(age_matri_q[5], age_matri_d[5], age_matri_upd[5], clk, rst_n)
    always_comb begin
        matrix_upd[0] = 6'b0;
        case (wr_id[0])
            2'd0: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][3] = wr_en[0];
            end
            2'd1: begin
                matrix_upd[0][0] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
            end
                        2'd2: begin
                matrix_upd[0][1] = wr_en[0];
                matrix_upd[0][2] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
            end
            2'd3: begin
                matrix_upd[0][3] = wr_en[0];
                matrix_upd[0][4] = wr_en[0];
                matrix_upd[0][5] = wr_en[0];
            end
        endcase
    end
    assign age_matri_upd = matrix_upd[0];
    always_comb begin
        matrix_d[0] = 6'b0;
        case (wr_id[0])
            2'd0: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][1] = write_vec[0][1];
                matrix_d[0][3] = write_vec[0][2];
            end
            2'd1: begin
                matrix_d[0][0] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][4] = write_vec[0][2];
            end
            2'd2: begin
                matrix_d[0][1] = write_vec[0][0];
                matrix_d[0][2] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
            end
            2'd3: begin
                matrix_d[0][3] = write_vec[0][0];
                matrix_d[0][4] = write_vec[0][1];
                matrix_d[0][5] = write_vec[0][2];
            end
        endcase
    end
    assign age_matri_d[0] = matrix_d[0][0];
    assign age_matri_d[1] = matrix_d[0][1];
    assign age_matri_d[2] = matrix_d[0][2];
    assign age_matri_d[3] = matrix_d[0][3];
    assign age_matri_d[4] = matrix_d[0][4];
    assign age_matri_d[5] = matrix_d[0][5];

    // Raw age vectors (without valid)
    assign age_vec_raw[0][0] = ~age_matri_q[0];
    assign age_vec_raw[0][1] = ~age_matri_q[1];
    assign age_vec_raw[0][2] = ~age_matri_q[3];
    assign age_vec_raw[1][0] =  age_matri_q[0];
    assign age_vec_raw[1][1] = ~age_matri_q[2];
    assign age_vec_raw[1][2] = ~age_matri_q[4];
    assign age_vec_raw[2][0] =  age_matri_q[1];
    assign age_vec_raw[2][1] =  age_matri_q[2];
    assign age_vec_raw[2][2] = ~age_matri_q[5];
    assign age_vec_raw[3][0] =  age_matri_q[3];
    assign age_vec_raw[3][1] =  age_matri_q[4];
    assign age_vec_raw[3][2] =  age_matri_q[5];
 
    // Generate age vectors on the basis of valid vector
if(FIND_OLDEST==1)  begin: age_matrix_gen_4_1_1_1_4_1_oldest_agev_gen
    assign age_vec[0][0][0] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[0][0][1] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[0][0][2] = !oldest_vld_vec[0][0] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[0][1][0] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[0][1][1] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[0][1][2] = !oldest_vld_vec[0][1] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[0][2][0] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[0][2][1] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[0][2][2] = !oldest_vld_vec[0][2] ? 1'b1 : (!oldest_vld_vec[0][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[0][3][0] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[0][3][1] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[0][3][2] = !oldest_vld_vec[0][3] ? 1'b1 : (!oldest_vld_vec[0][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[1][0][0] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[1][0][1] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[1][0][2] = !oldest_vld_vec[1][0] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[1][1][0] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[1][1][1] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[1][1][2] = !oldest_vld_vec[1][1] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[1][2][0] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[1][2][1] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[1][2][2] = !oldest_vld_vec[1][2] ? 1'b1 : (!oldest_vld_vec[1][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[1][3][0] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[1][3][1] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[1][3][2] = !oldest_vld_vec[1][3] ? 1'b1 : (!oldest_vld_vec[1][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[2][0][0] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[2][0][1] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[2][0][2] = !oldest_vld_vec[2][0] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[2][1][0] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[2][1][1] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[2][1][2] = !oldest_vld_vec[2][1] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[2][2][0] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[2][2][1] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[2][2][2] = !oldest_vld_vec[2][2] ? 1'b1 : (!oldest_vld_vec[2][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[2][3][0] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[2][3][1] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[2][3][2] = !oldest_vld_vec[2][3] ? 1'b1 : (!oldest_vld_vec[2][2] ? 1'b0 : age_vec_raw[3][2]);
    assign age_vec[3][0][0] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[0][0]);
    assign age_vec[3][0][1] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[0][1]);
    assign age_vec[3][0][2] = !oldest_vld_vec[3][0] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[0][2]);
    assign age_vec[3][1][0] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[1][0]);
    assign age_vec[3][1][1] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[1][1]);
    assign age_vec[3][1][2] = !oldest_vld_vec[3][1] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[1][2]);
    assign age_vec[3][2][0] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[2][0]);
    assign age_vec[3][2][1] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[2][1]);
    assign age_vec[3][2][2] = !oldest_vld_vec[3][2] ? 1'b1 : (!oldest_vld_vec[3][3] ? 1'b0 : age_vec_raw[2][2]);
    assign age_vec[3][3][0] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][0] ? 1'b0 : age_vec_raw[3][0]);
    assign age_vec[3][3][1] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][1] ? 1'b0 : age_vec_raw[3][1]);
    assign age_vec[3][3][2] = !oldest_vld_vec[3][3] ? 1'b1 : (!oldest_vld_vec[3][2] ? 1'b0 : age_vec_raw[3][2]);
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_4_1_1_1_4_1_newest_agev_gen
    assign age_vec_n[0][0][0] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[0][0]);
    assign age_vec_n[0][0][1] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[0][1]);
    assign age_vec_n[0][0][2] = !newest_vld_vec[0][0] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[0][2]);
    assign age_vec_n[0][1][0] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[1][0]);
    assign age_vec_n[0][1][1] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[1][1]);
    assign age_vec_n[0][1][2] = !newest_vld_vec[0][1] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[1][2]);
    assign age_vec_n[0][2][0] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[2][0]);
    assign age_vec_n[0][2][1] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[2][1]);
    assign age_vec_n[0][2][2] = !newest_vld_vec[0][2] ? 1'b1 : (!newest_vld_vec[0][3] ? 1'b0 : ~age_vec_raw[2][2]);
    assign age_vec_n[0][3][0] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][0] ? 1'b0 : ~age_vec_raw[3][0]);
    assign age_vec_n[0][3][1] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][1] ? 1'b0 : ~age_vec_raw[3][1]);
    assign age_vec_n[0][3][2] = !newest_vld_vec[0][3] ? 1'b1 : (!newest_vld_vec[0][2] ? 1'b0 : ~age_vec_raw[3][2]);
end
if(FIND_OLDEST==1)  begin: age_matrix_gen_4_1_1_1_4_1_oldest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_0 (
        .data(age_vec[0][0]),
        .cnt_oh(cnt_oh[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_0 (
        .data(age_vec[0][1]),
        .cnt_oh(cnt_oh[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_0 (
        .data(age_vec[0][2]),
        .cnt_oh(cnt_oh[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_0 (
        .data(age_vec[0][3]),
        .cnt_oh(cnt_oh[0][3])
    );
    assign oldest_rd_oh[0][0] = {cnt_oh[0][3][0], cnt_oh[0][2][0], cnt_oh[0][1][0], cnt_oh[0][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_1 (
        .data(age_vec[1][0]),
        .cnt_oh(cnt_oh[1][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_1 (
        .data(age_vec[1][1]),
        .cnt_oh(cnt_oh[1][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_1 (
        .data(age_vec[1][2]),
        .cnt_oh(cnt_oh[1][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_1 (
        .data(age_vec[1][3]),
        .cnt_oh(cnt_oh[1][3])
    );
    assign oldest_rd_oh[1][0] = {cnt_oh[1][3][0], cnt_oh[1][2][0], cnt_oh[1][1][0], cnt_oh[1][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_2 (
        .data(age_vec[2][0]),
        .cnt_oh(cnt_oh[2][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_2 (
        .data(age_vec[2][1]),
        .cnt_oh(cnt_oh[2][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_2 (
        .data(age_vec[2][2]),
        .cnt_oh(cnt_oh[2][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_2 (
        .data(age_vec[2][3]),
        .cnt_oh(cnt_oh[2][3])
    );
    assign oldest_rd_oh[2][0] = {cnt_oh[2][3][0], cnt_oh[2][2][0], cnt_oh[2][1][0], cnt_oh[2][0][0]};
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_3 (
        .data(age_vec[3][0]),
        .cnt_oh(cnt_oh[3][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_3 (
        .data(age_vec[3][1]),
        .cnt_oh(cnt_oh[3][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_3 (
        .data(age_vec[3][2]),
        .cnt_oh(cnt_oh[3][2])
    );
        wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_3 (
        .data(age_vec[3][3]),
        .cnt_oh(cnt_oh[3][3])
    );
    assign oldest_rd_oh[3][0] = {cnt_oh[3][3][0], cnt_oh[3][2][0], cnt_oh[3][1][0], cnt_oh[3][0][0]};
end
if(FIND_NEWEST==1)  begin: age_matrix_gen_4_1_1_1_4_1_newest_cnt
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u0_0 (
        .data(age_vec_n[0][0]),
        .cnt_oh(cnt_oh_n[0][0])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u1_0 (
        .data(age_vec_n[0][1]),
        .cnt_oh(cnt_oh_n[0][1])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u2_0 (
        .data(age_vec_n[0][2]),
        .cnt_oh(cnt_oh_n[0][2])
    );
    wing_cbb_prefix_counter #(
        .DATA_WIDTH(3),
        .NUM_OF_ONES(0)
    ) wing_cbb_prefix_counter_3_0_u3_0 (
        .data(age_vec_n[0][3]),
        .cnt_oh(cnt_oh_n[0][3])
    );
    assign newest_rd_oh[0][0] = {cnt_oh_n[0][3][0], cnt_oh_n[0][2][0], cnt_oh_n[0][1][0], cnt_oh_n[0][0][0]};
end
if(FIND_OLDEST==0)  begin: age_matrix_gen_4_1_1_1_4_1_no_oldest
    assign age_vec = 'b0;
    assign cnt_oh = 'b0;
    assign oldest_rd_oh = 'b0;
end
if(FIND_NEWEST==0)  begin: age_matrix_gen_4_1_1_1_4_1_no_newest
    assign age_vec_n = 'b0;
    assign cnt_oh_n = 'b0;
    assign newest_rd_oh = 'b0;
end
end
 
endmodule
`include "chunjun_undefine.sv" 
